开发中,ActionSheet主要用于选择,系统提供的有:
UIActionSheet (iOS 8.3废弃)
UIAlertController (iOS8.0开发代替UIActionSheet和UIAlertView(iOS9.0废弃))
组件中提供了一种默认样式(类似微信)和系统样式,如果需要其他样式可以自定义,具体的用法可参看Demo
组件支持cocoapods
pod "ZHActionSheet"
下面是示例
系统样式
示例图片
示例代码
ZHActionSheet *actionSheet = [[ZHActionSheet alloc] initActionSheetWithTitle:@"ActionSheet" contents:@[@"一",@"二",@"三",@"四",@"五"] cancels:@[@"取消",@"删除"]];
actionSheet.actionSheetType = ActionSheetTypeSystem;
actionSheet.subtitle = @"System Type";
[actionSheet addContent:@"〇" atIndex:0];
[actionSheet addContent:@"六" atIndex:6];
[actionSheet removeContentAtIndex:0];
[actionSheet setClickedContent:^(ZHActionSheet *actionSheet, NSUInteger index) {
NSLog(@"==========ZHActionSheet click at index %ld", index);
}];
[actionSheet show];
默认样式
示例图片
示例代码
ZHActionSheet *actionSheet = [[ZHActionSheet alloc] initActionSheetWithTitle:@"ActionSheet" contents:@[@"一",@"二",@"三",@"四",@"五"] cancels:@[@"取消",@"删除"]];
actionSheet.actionSheetType = ActionSheetTypeDefault;
actionSheet.subtitle = @"Default Type";
[actionSheet addContent:@"〇" atIndex:0];
[actionSheet addContent:@"六" atIndex:6];
[actionSheet setCancelAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20],NSForegroundColorAttributeName:[UIColor purpleColor]} atIndex:0];
[actionSheet setCancelAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20],NSForegroundColorAttributeName:[UIColor redColor]} atIndex:1];
[actionSheet setClickedContent:^(ZHActionSheet *actionSheet, NSUInteger index) {
NSLog(@"==========ZHActionSheet click content at index %ld", index);
}];
actionSheet.clickedCancle = ^(ZHActionSheet *actionSheet, NSUInteger index) {
NSLog(@"==========ZHActionSheet click cancel at index %ld", index);
};
[actionSheet show];
自定义样式
示例图片
1.竖屏
2.横屏
示例代码
ZHActionSheet *actionSheet = [ZHActionSheet actionSheetWithTitle:nil contents:self.dataSource cancels:nil];
actionSheet.actionSheetType = ActionSheetTypeCustom;
//actionSheet.dataSource = self;
actionSheet.delegate = self;
actionSheet.itemNib = [UINib nibWithNibName:@"ActionSheetItemCell" bundle:nil];
actionSheet.itemHeight = 60;
actionSheet.itemForActionSheet = ^UITableViewCell *(ZHActionSheet *actionSheet, UITableView *tableView, NSString *identifier, NSIndexPath *indexPath) {
ActionSheetItemCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
cell.image.image = [UIImage imageNamed:self.dataSource[indexPath.row]];
cell.label.text = self.dataSource[indexPath.row];
return cell;
};
[actionSheet show];
//代理
- (void)actionSheet:(ZHActionSheet *)actionSheet clickedContentAtIndex:(NSUInteger)index {
NSLog(@"==========ZHActionSheet click content %@ at index %ld", self.dataSource[index], index);
}