您的位置:首页 > 产品设计 > UI/UE

iOS UITableViewCell 左滑删除时,修改删除按钮背景颜色,默认是红色的

2017-03-24 09:55 441 查看
方法1:

1 // 自定义左滑显示编辑按钮
2 -(NSArray<UITableViewRowAction*>*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
3 {
4
5     UITableViewRowAction *rowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault
6                                                                          title:@"跟进" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
7                                                                              NSLog(@"跟进");
8
9                                                                          }];
10
11     UITableViewRowAction *rowActionSec = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault
12                                                                             title:@"快速备忘"    handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
13                                                                                 NSLog(@"快速备忘");
14
15                                                                             }];
16     rowActionSec.backgroundColor = [UIColor colorWithHexString:@"f38202"];
17     rowAction.backgroundColor = [UIColor colorWithHexString:@"d9d9d9"];
18
19     NSArray *arr = @[rowAction,rowActionSec];
20     return arr;
21 }


方法2:

开发中可能会有改变这个按钮背景色的需求,如微信的通讯录左滑备注按钮就是灰色的,实现这个需求我们需要自定义cell,在自定义的cell中重写layoutSubviews这个方法,找到UITableViewCellDeleteConfirmationView修改它的背景色即可。

1 - (void)layoutSubviews
2 {
3     [super layoutSubviews];
4
5     for (UIView *subView in self.subviews) {
6         NSString *subViewName =NSStringFromClass([subView class]);
7         if ([subViewName isEqualToString:@"UITableViewCellDeleteConfirmationView"]) {
8             subView.backgroundColor = [UIColor lightGrayColor];
9             ((UIView *)[subView.subviews firstObject]).backgroundColor = [UIColor lightGrayColor];
10
11         }
12     }
13 }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: