我正在尝试创建图像的滚动视图,并像应用商店屏幕截图一样可点击,当用户触摸一张图像时,会调用一些操作!但在这里我找不到这行不通的问题!请注意,我使用的所有 UI 都是由代码制作的!
func initScreenshots(){
if screenShotsView.subviews.count > 0{
screenShotsView.subviews.forEach({ $0.removeFromSuperview() })
}
imageArray.append(UIImage.init(named: "1.jpeg")!)
imageArray.append(UIImage.init(named: "2.jpeg")!)
for image in imageArray {
let index = imageArray.index(of: image)
let imageView:UIImageView = {
let iv = UIImageView()
iv.image = image
iv.translatesAutoresizingMaskIntoConstraints = false
iv.contentMode = .scaleAspectFit
return iv
}()
imageView.isUserInteractionEnabled = true
imageView.addGestureRecognizer(tapGesture)
screenShotsView.addSubview(imageView)
imageView.topAnchor.constraint(equalTo: screenShotsView.topAnchor, constant: 10).isActive = true
imageView.bottomAnchor.constraint(equalTo: screenShotsView.bottomAnchor, constant: 10).isActive = true
imageView.heightAnchor.constraint(equalToConstant: 350).isActive = true
imageView.widthAnchor.constraint(equalToConstant: 190).isActive = true
if index == 0 {
imageView.leftAnchor.constraint(equalTo: screenShotsView.leftAnchor, constant: …Run Code Online (Sandbox Code Playgroud) 我正在开发一个多语言应用程序,\n在某些地方我需要计算英语字符和阿拉伯语字符来决定
\n\nnameLabel.textAlignment = .right\nRun Code Online (Sandbox Code Playgroud)\n\n或者
\n\nnameLabel.textAlignment = .left\nRun Code Online (Sandbox Code Playgroud)\n\n例如像这样的一些文本:
\n\n\n\n\n\xd8\xa8\xd8\xa7\xd8\xb2\xdb\x8c 愤怒的小鸟 \xd8\xa8\xd8\xb3\xdb\x8c\xd8\xa7\xd8\xb1 \xd8\xa8\xd8\xa7\xd8\xb2 \xdb\x8c \xd8\xac\xd8\xb0\xd8\xa7\xd8\xa8\xdb\x8c \xd8\xa7\xd8\xb3\xd8\xaa
\n
需要.right文本对齐和
\n\n\n愤怒的小鸟是一款令人兴奋的游戏
\n
需要.left文本对齐!\n我想通过计算服务器中的英语和非英语字符来判断这一点。
这里的最佳实践是什么?
\n我是在没有 interface builder 的情况下创建视图的新手。我正在使用NSLayoutAnchors创建视图!
当我使用在 viewcontroller 中创建的一些视图时:
let borderView:UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = UIColor.lightGray
view.isUserInteractionEnabled = false
view.alpha = 0.5
return view
}()
Run Code Online (Sandbox Code Playgroud)
然后我使用这个视图来边界这样的视图:
view.addSubview(borderView)
borderView.bottomAnchor.constraint(equalTo: headerView.bottomAnchor).isActive = true
borderView.leftAnchor.constraint(equalTo: headerView.leftAnchor).isActive = true
borderView.rightAnchor.constraint(equalTo: headerView.rightAnchor).isActive = true
borderView.heightAnchor.constraint(equalToConstant: 1).isActive = true
Run Code Online (Sandbox Code Playgroud)
然后在另一个视图中我尝试这个:
informationView.addSubview(borderView)
borderView.topAnchor.constraint(equalTo: informationView.topAnchor).isActive = true
borderView.leftAnchor.constraint(equalTo: informationView.leftAnchor).isActive = true
borderView.rightAnchor.constraint(equalTo: informationView.rightAnchor).isActive = true
borderView.heightAnchor.constraint(equalToConstant: 1).isActive = true
Run Code Online (Sandbox Code Playgroud)
但看起来这个视图有它以前的约束结束显示约束错误!
如何borderView在重用之前删除约束?