【发布时间】:2017-09-22 18:45:13
【问题描述】:
我正在使用 XCode 版本 9.0 (9A235)、macOS Sierra 版本 10.12.6 (16G29)、iOS 11.0。
我需要将约束添加到数组中,然后我需要激活它。
我确实喜欢这样做......
// 1.Declare and initialized the constraint
private lazy var labelConstraints = [NSLayoutConstraint]()
// 2.Prepare constraint
let widthConstraint =
headerLabel.widthAnchor.constraint(equalTo: licenseLabel.widthAnchor)
// 3.Constraint added into the array
labelConstraints.append(NSLayoutConstraint(widthConstraint))
// 4.Finally activate the constraints
labelConstraints.activate()
在构建我的 xcode 项目后,它会引发类似
的错误ERROR: **cannot invoke initializer for type 'NSLayoutConstraint' with an argument list of type '(NSLayoutConstraint)'**
**labelConstraints.append(NSLayoutConstraint(widthConstraint))**
【问题讨论】:
-
请尝试更好地格式化您的问题。不要以
-开头,因为这会使stackoverflow 将其视为列表项。将代码 sn-ps 缩进额外的四个空格。这次我给你修好了。