zoukankan      html  css  js  c++  java
  • iOS UITableViewCell 左滑删除时,修改删除按钮背景颜色,默认是红色的

    方法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 }
  • 相关阅读:
    CentOS+Nginx+PHP+MySQL详细配置(图解)
    linux下MySQL安装登录及操作
    hdu 1059 多重背包
    hdu 1754 单点更新
    poj 3264 RMQ 水题
    hdu 1114 基础完全背包
    hdu 3466 排序01背包
    poj 2923 状压dp+01背包
    hdu 2639 第k大01背包
    hdu 2184 01背包变形
  • 原文地址:https://www.cnblogs.com/codemakerhj/p/6609883.html
Copyright © 2011-2022 走看看