iOS之tableView左划显示多个按钮(适配iOS11)

一,说明

tableView左划出现多个可点击的按钮, 网上也有很多,但是大部分都是要iOS8以上的系统版本,不符合我的APP需求.   所以我写了一个是基于iOS7及以上系统版本的,同时要高度封装.demo的地址在本文的最后面.

效果1:



这个效果是基于系统原生的.
首先创建自定义cell 命名:LCDeleteTableViewCell,继承UITableViewCell. 这里的效果1图显示的是2个按钮,所以我们要便利cell的子视图,将原来系统的一个按钮remove掉,添加我们自定义的2个按钮到视图上.注意:这里的视图类型是: UITableViewCellDeleteConfirmationView 
以下是代码片段:
- (void)createManyButton{
    for (UIView *subView in self.subviews) {
        if ([subView isKindOfClass:NSClassFromString(@"UITableViewCellDeleteConfirmationView")]) {
            subView.backgroundColor=[UIColor lightGrayColor];
            for (UIButton *btn in subView.subviews) {
                if ([btn isKindOfClass:[UIButton class]]) {
                    [btn removeFromSuperview];//将系统原生的删除按钮remove掉
                }
            }
            //在此自定义多个按钮,并添加(注:添加到的视图类型是:@"UITableViewCellDeleteConfirmationView")
            _deleteButton=[self createDeleteButton];
            _deleteButton.frame=CGRectMake(0, 0, subView.frame.size.width/2, subView.frame.size.height);
            [subView addSubview:_deleteButton];
            _downLoadButton=[self createDownLoadButton];
            _downLoadButton.frame=CGRectMake(subView.frame.size.width/2, 0, subView.frame.size.width/2, subView.frame.size.height);
            if (downLoadLableText.length==0) {
                downLoadLableText=@"下载";
            }
            [_downLoadButton setTitle:downLoadLableText forState:UIControlStateNormal];
            [subView addSubview:_downLoadButton];
        }
    }

}
//懒加载
- (UIButton *)createDeleteButton{
    if (!_deleteButton) {
        _deleteButton=[UIButton buttonWithType:UIButtonTypeCustom];
        _deleteButton.backgroundColor=[UIColor redColor];
        [_deleteButton setTitle:@"删除" forState:UIControlStateNormal];
        _deleteButton.titleLa
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值