我收到指向第一个参数的错误“调用中的额外参数”。
let imageView = UIImageView()
let imageHeight = 10.0
let heightConstraint = NSLayoutConstraint(imageView, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .Height, multiplier: 1.0, constant: imageHeight)
我也尝试过使用 item: imageView,...
,但我得到了同样的错误。
最佳答案
我认为问题是 imageHeight 是双倍的,但构造函数需要一个 CGFloat,所以试试
let imageHeight: CGFloat = 10.0
看起来还有一件小事:
NSLayoutConstraint(item: imageView, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .Height, multiplier: 1.0, constant: imageHeight)
您在 imageView 之前离开了该项目,但您已经提到了这一点。
关于xcode - 如何在 swift 中实例化 NSLayoutConstraint? (Xcode 6.1.1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27706533/