封装组件ActionSheet,可以自定义Item,支持屏幕旋转

开发中,ActionSheet主要用于选择,系统提供的有:
UIActionSheet (iOS 8.3废弃)
UIAlertController (iOS8.0开发代替UIActionSheet和UIAlertView(iOS9.0废弃))

组件中提供了一种默认样式(类似微信)和系统样式,如果需要其他样式可以自定义,具体的用法可参看Demo

组件支持cocoapods

pod "ZHActionSheet"

下面是示例

系统样式

示例图片

system.PNG

示例代码

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];

默认样式

示例图片

default.PNG

示例代码

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.竖屏


custom.PNG

2.横屏


custom_ landscape.PNG

示例代码

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);
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 这个小东西,可以说完美满足我的需要,简直就是我心里想要的样子。 虽然这个logo做得有点无趣,但是功能十分能打。 ...
    闪芃芃阅读 3,266评论 2 4
  • 2018年3月5星期一天气晴 时间过得真快,转眼间寒假就结束了。开学前的晚上,宝贝心情很激动,在床上翻来复去睡...
    冬末初春阅读 126评论 0 0
  • NodeJs 操作数据库详解 1. 引入mongodb模块 var mongoclient = require("...
    一顾SAMA阅读 256评论 0 0
  • 036 037 038 039 045 047 049 054 056 057 059 061 063 065 0...
    糖果_da36阅读 329评论 1 0