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

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

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

组件支持cocoapods

pod "ZHActionSheet"

下面是示例

系统样式

示例图片
2014390-df752a376c55dd94.PNG
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];

默认样式

示例图片
2014390-997d995d1e621f7a.PNG
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.竖屏


2014390-cb7d61274aae86d2.PNG
custom.PNG

2.横屏


2014390-9711095875a4933b.PNG
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);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值