我需要一些帮助来使用自动布局实现此 UI
我正在以编程方式创建 UIButtons
for (int i=0; i<10; i++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.backgroundColor = [UIColor greenColor];
[btn sizeToFit];
[btn setTitle:@"user@example.com" forState:UIControlStateNormal];
[self.myCustomView addSubview:btn];
}
myCustomView 是在 XIB 中创建的 UIView。我已将 myCustomView 的前导、尾随和顶部边缘固定到其 superview 。我已将 myCustomView 的高度设置为 44。
我需要使用约束将 UIButtons 作为 subview 添加到 myCustomView 中,以便按钮应换行到下一行,并且 myCustomView 应根据其 subview 内容增加其高度。
http://i41.tinypic.com/3536ob6.png
实现此目的的代码片段会很有帮助
最佳答案
如果您想以编程方式使用自动布局,您可以使用 NSLayoutConstraint 或 Parus 库 https://github.com/DAlOG/Parus 来实现它
关于ios - 使用自动布局将多个 UIButtons 作为 subview 添加到 UIview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19381329/