这是有问题的代码
// auto layout
let vertivalConstraint = textField.centerYAnchor.constraint(equalTo: self.codeView.centerYAnchor)
let leadingConstraint = textField.leadingAnchor.constraint(equalTo: self.codeView.leadingAnchor, constant: 10)
let trailingConstraint = textField.trailingAnchor.constraint(equalTo: self.codeView.trailingAnchor, constant: -10)
let heightConstraint = textField.heightAnchor.constraint(equalTo: nil, constant: 37)
NSLayoutConstraint.activate([leadingConstraint, vertivalConstraint, trailingConstraint, heightConstraint])
让heightConstraint返回标题中的错误。我该如何解决这个问题。
由于
答案 0 :(得分:1)
也许试试:
// auto layout
let vertivalConstraint = textField.centerYAnchor.constraint(equalTo: self.codeView.centerYAnchor)
let leadingConstraint = textField.leadingAnchor.constraint(equalTo: self.codeView.leadingAnchor, constant: 10)
let trailingConstraint = textField.trailingAnchor.constraint(equalTo: self.codeView.trailingAnchor, constant: -10)
let heightConstraint = textField.heightAnchor.constraint(equalToConstant: 37)
NSLayoutConstraint.activate([leadingConstraint, vertivalConstraint, trailingConstraint, heightConstraint])
我正在使用:
.constraint(equalToConstant: 37)
而不是:
.heightAnchor.constraint(equalTo: nil, constant: 37)