ios - 使用自动布局将多个 UIButtons 作为 subview 添加到 UIview

标签 ios xcode5

我需要一些帮助来使用自动布局实现此 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/

相关文章:

ios - 如何让我的动画功能 swift 依赖于 objective-c 麦克风打击检测?

ios - UIButton 按下时不可选择,并且不会在自定义 UICollectionReusableView 中继续

ios - 我应该将图像保存在 Core Data 中还是应该使用 SDWebImage

ios - 可以从 XCTest 中的其他测试用例中调用测试用例

ios - 在没有 UDID 的多台机器上测试 IOS 应用程序

ios - 在 Objective c 中设置整数值

iphone - 下载 iOS SDK 应用程序

c - Xcode 5.1.1 构建失败 C 编程

objective-c - 将 Cocoa 应用程序和命令行工具合并到一个应用程序包中

ios:如何使用 StoryBoards 从 ViewController 打开 Tab Bar Controller