模仿微信的 ActionSheet。支持修改文字颜色,支持多行。
使用 cocoapods
Podfile
中添加 pod 'HZActionSheet'
.pod update
.Masonry
,所以最终下载的源码也包括 Masonry
。有关 Masonry
的信息,大家可以自行 google
。不使用 cocoapods
HZActionSheet
.Masonry
。添加代码
创建 HZActionSheet
HZActionSheet *sheet = [[HZActionSheet alloc] initWithTitle:@"选择照片" delegate:self cancelButtonTitle:@"取消" destructiveButtonIndexSet:nil otherButtonTitles:@[@"相册", @"相机"]];
destructiveButton
传递的是一个 IndexSet
。
显示 HZActionSheet
[sheet showInView:self.view];
HZActionSheet
是添加到 view
的 window
上的,因此不需要传递 view.window
属性。
点击按钮在 delegate
中处理
- (void)actionSheet:(HZActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (actionSheet.cancelButtonIndex != buttonIndex) {
NSLog(@"你点击了 %@", @(buttonIndex));
}
}
给按钮设置其他颜色
sheet.titleColor = [UIColor purpleColor];