【发布时间】:2016-02-09 05:02:41
【问题描述】:
我有一个用户表单,其中有一堆标签及其相应的文本字段或下拉菜单或复选框组,在 Storyboard 上垂直排列。像这样的:
Label 1
Text Field 1
Label 2
Check Box Group
Label 3
Drop Down Field
Label 4
Text Field 4
正常情况下,Label之间设置的约束为垂直60。
问题是由于复选框组是从服务器检索的数据动态填充的,我不知道在 StoryBoard 设计时标签 2 和标签 3 之间会有多少复选框。因此需要以编程方式更改标签 2 和标签 3 之间的约束。
目前,我所做的是在它们之间设置约束 60,但选中“在构建时删除”并根据它们之间有多少复选框以编程方式设置约束。像这样的:
[_superView addConstraint:[NSLayoutConstraint constraintWithItem:_Label3 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_Label2 attribute:NSLayoutAttributeBottom multiplier:1 constant:100]];
但由于某些原因,这并没有按预期工作。尽管 Label3 正确放置在最后一个复选框之后,但我只能看到具有高度限制的 Label4 的一半。我试过了:
[superView updateConstraints];
[superView layoutIfNeeded];
但无济于事。
【问题讨论】:
标签: ios storyboard nslayoutconstraint