我试图放置一个标签,使标签的顶部位于 UIViewController 下方的 2/3 处。所以我写了这个约束,但它给了我下面的错误。
NSLayoutConstraint *labelTopConstraint = [NSLayoutConstraint constraintWithItem:self.myLabel
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationGreaterThanOrEqual
toItem:self.view
attribute:NSLayoutAttributeHeight
multiplier:0.66
constant:0];
错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '*** +[NSLayoutConstraint
constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]:
Invalid pairing of layout attributes'
最佳答案
是的,这很烦人,不是吗?假设您的 View Controller 是屏幕的全高,您可以使用 NSLayoutAttributeBottom 而不是高度,这应该会给您相同的结果。
关于ios - 为什么 UIViewController.UIView 对子 UIViewLabel 的约束抛出错误 "Invalid pairing of layout attributes"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16128372/