Swift 修改系统UITableViewCell的删除按钮样式

场景一:

// 自定义左滑显示编辑按钮
-(NSArray<UITableViewRowAction*>*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewRowAction *rowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault
                                                                         title:@"跟进" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
        NSLog(@"跟进");
    }];
    
    UITableViewRowAction *rowActionSec = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault
                                          title:@"快速备忘"    handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
        NSLog(@"快速备忘");
        
    }];
    rowActionSec.backgroundColor = [UIColor colorWithHexString:@"f38202"];
    rowAction.backgroundColor = [UIColor colorWithHexString:@"d9d9d9"];
    NSArray *arr = @[rowAction,rowActionSec];
    return arr;
}

场景二:

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

#pragma mark - Encryption

- (NSData *)encryptedValue:(NSData *)value {
    // Generate IV
    NSData *iv = [SFCryptoUtils generateInitializationVector];

    // Fetch encryption key
    SFSecureStore *store = [SFSecureStore createUserStoreHandlerForScope:SFSecureStoreScopeLearning];
    NSData *key = [store coreDataEncryptionKeyOfDataVault];

    // Encrypt data
    NSData *encryptedData = [SFCryptoUtils encryptDataWithIntegrityProtection:value withKey:key withInitializationVector:iv];

    // Concatinate IV + SHA256 + encrypted data
    NSMutableData *finalValue = [NSMutableData new];
    [finalValue appendData:iv];
    [finalValue appendData:encryptedData];

    // Validate the sizes of these data objects haven't changed during development, throwing off decryption
    NSAssert1(iv.length == LMS_IV_LENGTH, @"IV length is now %lu", (long unsigned)iv.length);

    return [finalValue copy];
}

场景三:

//系统自带Cell 删除按钮样式修改:
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
        return .delete
    }

public override func layoutSubviews() {
        super.layoutSubviews()
        
        if let views = self.superview?.subviews {
            for aView in views {
                let viewName = NSStringFromClass(type(of: aView).self)
                if viewName == "UISwipeActionPullView" {
                    aView.subviews.forEach { $0.backgroundColor = SSFTheme.Color.negativeLabel }
                }
            }
        }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值