iOS左滑插入多个按钮,按钮自定义颜色、图片、文字字体等
来源:互联网 发布:数据库软件排行 编辑:程序博客网 时间:2024/05/16 18:59
iOS8.0之后UITableView新添加了,左滑可以添加多个按钮的方法
- (nullable NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{ __weak typeof(self) weakSelf = self; NSMutableArray *array = [NSMutableArray array]; //插入多个按钮,按钮位置排序0~4,从右向左 for(int i=0; i<4; i++){ __block NSInteger tag = i; UITableViewRowAction *rowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@" " handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) { [weakSelf tapRowAction:indexPath.row type:tag]; }]; rowAction.backgroundColor = HEX_COLOR(@"afb6c1"); [array addObject:rowAction]; } return array;}- (void)tapRowAction:(NSInteger)row type:(NSInteger)type{ if(type==0){ [[[CommonUIAlert alloc] init] showCommonAlertView:self title:@"" message:@"是否删除该名片" cancelButtonTitle:@"取消" otherButtonTitle:@"确定" cancle:^{ } confirm:^{ [self.dataArray removeObjectAtIndex:row]; [self.tableView beginUpdates]; [self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:row inSection:0]] withRowAnimation:UITableViewRowAnimationFade]; [self.tableView endUpdates]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self.tableView reloadData]; }); }]; }else if(type==1){ CardGroupViewController *vc = [CommonMethod getVCFromNib:[CardGroupViewController class]]; vc.isShowGroupList = NO; [self.navigationController pushViewController:vc animated:YES]; }else if(type==2){ NSString *str = [NSString stringWithFormat:@"tel:%@",@"15261173162"]; UIWebView *callWebView = [[UIWebView alloc]init]; [callWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]]; [self.view addSubview:callWebView]; }else{ [self showMessageView:[NSArray arrayWithObjects:@"15261173162", nil] title:@""]; }}
自定义左滑按钮,UITableViewRowAction,在你自定义的cell或者UITableViewCell中,重写-(void)layoutSubviews方法
- (void)layoutSubviews{ for (UIView *subView in self.subviews) { if([subView isKindOfClass:NSClassFromString(@"UITableViewCellDeleteConfirmationView")]) { NSArray *array = @[@"icon_mp_dete",@"icon_mp_fz",@"icon_mp_tele",@"icon_mp_message"]; for(int i=0; i<4; i++){ UIView *btnView = subView.subviews[i]; btnView.backgroundColor = HEX_COLOR(@"afb6c1"); for (UIView *btn in btnView.subviews) { UIImageView *imageview = [[UIImageView alloc] init]; imageview.contentMode = UIViewContentModeScaleAspectFit; imageview.image = kImageWithName(array[i]); imageview.frame = CGRectMake(0, 0, btn.frame.size.width, btn.frame.size.height); [btn addSubview:imageview]; } } } }}
效果如下:
阅读全文
0 0
- iOS左滑插入多个按钮,按钮自定义颜色、图片、文字字体等
- iOS 按钮文字左对齐
- 自定义一个文字居左图片居右的按钮
- iOS如何设置按钮左文字右图片
- IOS 按钮字体颜色设置
- iOS 更改tabbar字体颜色 自定义controller返回按钮
- iOS -- 设置按钮中的文字左对齐
- iOS心得7 按钮的图片和文字自定义位置
- UITableView左滑出现多个按钮
- tabviewcell 左滑 自定义按钮
- tableview自定义左滑按钮
- UITableView自定义左滑删除按钮(带图片)
- iOS自定义返回按钮左滑返回失效问题
- Swift里自定义一个文字在左、图片在右的,标题按钮
- 导航栏添加自定义按钮(图片在左文字在右)
- iOS 修改UIAlertController的按钮字体颜色
- iOS之tableView左划显示多个按钮
- 按钮,字体,图片,等,置灰实现
- Jobs added with no trigger must be durable
- commons.lang中常用的工具类
- 逻辑结构和存储结构
- IntelliJ Idea 2017 免费激活方法
- HDU-1022-Train Problem I
- iOS左滑插入多个按钮,按钮自定义颜色、图片、文字字体等
- spring boot devtools 热部署工具
- Android 屏幕适配:最全面的解决方案
- Speed/accuracy trade-offs for modern convolutional object detectors
- 文本编辑工具VIM
- 四种常见排序算法C++实现
- redis:学习路程
- 学生信息管理系统之ASCII问题汇总
- android studio打包以及gradle配置构建