Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试为iOS编程锚定映像_Ios_User Interface_Anchor - Fatal编程技术网

尝试为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行,除非有什么东西加入了一个扩展来改变语言。如果你正在使用这样的扩展,你需要告诉我们。哦,对不起,可能是打字错误。这些手指自己打字。