gpt4 book ai didi

ios - 为什么 UIViewController.UIView 对子 UIViewLabel 的约束抛出错误 "Invalid pairing of layout attributes"?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:58:58 27 4
gpt4 key购买 nike

我试图放置一个标签,使标签的顶部位于 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com