似乎标签位置不正确,因为它没有任何约束。
你可以试试下面的代码吗?
label.translatesAutoresizingMaskIntoConstraints = false
let topConstraint = NSLayoutConstraint(item: label, attribute: .Top, relatedBy: .Equal, toItem: textField, attribute: .Top, multiplier: 1.0, constant: 0.0)
let leftConstraint = NSLayoutConstraint(item: label, attribute: .Left, relatedBy: .Equal, toItem: textField, attribute: .Left, multiplier: 1.0, constant: 0.0)
let bottomConstraint = NSLayoutConstraint(item: label, attribute: .Bottom, relatedBy: .Equal, toItem: textField, attribute: .Bottom, multiplier: 1.0, constant: 0.0)
let rightConstraint = NSLayoutConstraint(item: label, attribute: .Right, relatedBy: .Equal, toItem: textField, attribute: .Right, multiplier: 1.0, constant: 0.0)
self.view.insertSubview(label, belowSubview: textField)
NSLayoutConstraint.activateConstraints([topConstraint, leftConstraint, bottomConstraint, rightConstraint])
您是否正确设置了要添加的视图的x:y坐标?请注意,上面的插入是关于z顺序的,而不是x:y的位置。 – Verticon