尝试为iOS编程锚定映像
这是我的密码尝试为iOS编程锚定映像,ios,user-interface,anchor,Ios,User Interface,Anchor,这是我的密码 import UIKit class PageCell: UICollectionViewCell { override init(frame: CGRect) { super.init(frame: frame) setupViews() } let imageView: UIImageView = { let iv = UIImageView() iv.contentMode = .
import UIKit
class PageCell: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
}
let imageView: UIImageView = {
let iv = UIImageView()
iv.contentMode = .scaleAspectFill
iv.backgroundColor = .yellow
iv.image = UIImage(named: "page1")
return iv
}()
func setupViews() {
backgroundColor = .blue
addSubview(imageView)
imageView.(topAnchor, bottomAnchor, rightAnchor, leftAnchor)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
编译时会显示此错误<代码>类型为“UIImageView”的值没有成员“anchorToTop”我尝试将图像锚定到单个UIImageViewCell。您可以尝试
func setupViews() {
backgroundColor = .blue
imageView.translatesAutoresizingMaskIntoConstraints = false
self.contentView.addSubview(imageView)
imageView.topAnchor.constraint(equalTo: self.contentView.topAnchor, constant: 0 ).isActive = true
imageView.bottomAnchor.constraint(equalTo: self.contentView.bottomAnchor, constant: 0 ).isActive = true
imageView.leftAnchor.constraint(equalTo: self.contentView.leftAnchor, constant: 0 ).isActive = true
imageView.rightAnchor.constraint(equalTo: self.contentView.rightAnchor, constant: 0 ).isActive = true
}
用什么语言或API说
imageView是合法的(topAnchor、bottomAnchor、rightAnchor、leftAnchor)
?这不是一个有效的Swift行,除非有什么东西加入了一个扩展来改变语言。如果你正在使用这样的扩展,你需要告诉我们。哦,对不起,可能是打字错误。这些手指自己打字。