【发布时间】:2013-10-15 12:31:26
【问题描述】:
我需要一些帮助来使用 Autolayout 实现这个 UI
我正在以编程方式创建 UIButton
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 作为子视图添加到 myCustomView,这样按钮应该换行到下一行,myCustomView 应该根据其子视图内容增加其高度。
http://i41.tinypic.com/3536ob6.png
实现这一点的代码片段会有所帮助
【问题讨论】:
-
如果您以编程方式添加按钮,则必须指定框架大小...
-
您确定要添加帧大小吗?自动布局是为了自己处理框架对吧?
-
stackoverflow.com/questions/12593153/… 访问链接可能不是关于按钮,而是一些关于自动布局的信息