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 }
  • 相关阅读:
    用栈消除递归调用,实现DFS【伪代码】
    B树残缺版
    lvm
    RAID独立冗余磁盘阵列
    压缩、归档
    磁盘、文件系统
    setfacl、getfacl
    locate,find
    vim编辑器
    sed流编辑器
  • 原文地址:https://www.cnblogs.com/codemakerhj/p/6609883.html
Copyright © 2011-2022 走看看