包含一组水平放置在圆角矩形中的按钮的 UIView。
MWButtonGroup
为 ARC 编写,需要 iOS 7.0+(但应该也适用于早期版本)。目前不需要其他依赖。
最好使用 CoconutPods 来安装 MWButtonGroup
(请参阅 https://cocoapods.org.cn)。
将以下行添加到您的 Podfile 中:
pod 'MWButtonGroup' , :git=> 'https://github.com/zliw/MWButtonGroup.git'
用法示例可在外部 MWButtonGroup-Example
目录中查看。
初始化视图的方式与任何其他 UIView 子类一样(或可以在界面构建器中创建)。遗憾的是,视图的样式必须通过代码实现。
MWButtonGroup *group = [[MWButtonGroup alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
可以通过指定它们的标签作为字符串来添加按钮
[group createButtonsForTitles:@[@"Yes", @"No", @"Maybe"]]
默认情况下,多选是关闭的。您可以通过设置属性来启用它。
group.coloredButtonGroup.multiSelectAllowed = YES;
默认颜色方案为黑色和白色。您可以设置以下颜色属性。
group.textColor = [UIColor yellowColor];
group.buttonBackgroundColor = [UIColor colorWithRed:0 green:0.25 blue:0 alpha:1];
可以为按钮组中包含的所有按钮设置字体
group.font = [UIFont fontWithName:@"HelveticaNeue" size:16];
此组件在 MIT 许可下提供。有关详细信息,请参阅 许可证 文件。