首页 > 移动平台 > 详细

iOS UItable view cell 左滑删除

时间:2020-10-17 11:42:51      阅读:31      评论:0      收藏:0      [点我收藏+]

实现自定义左滑删除修改背景颜色以及字体颜色,目前ios9 和ios11有两种方式可以实现左滑删除功能

1、iOS9

- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{

    [tableView setEditing:NO animated:YES];

    UITableViewRowAction *action = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath){

  //TODO 进行删除相关的代码

    }];

   //设置背景颜色

 action.backgroundColor = [UIColor colorWithHexString:@"#FFBE11"];

   //设置删除按钮文字颜色

 [[UIButton appearanceWhenContainedInInstancesOfClasses:@[[LikeMyUsersViewController class]]] setTitleColor:[UIColor colorWithHexString:@"#0A0A0A"] forState:UIControlStateNormal];

    return @[action];

}

2、iOS11

- ( UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath  API_AVAILABLE(ios(11.0)){

    //删除

    if (@available(iOS 11.0, *)) {

        UISwipeActionsConfiguration *config;

        UIContextualAction *deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {

   //TODO 进行删除相关的代码逻辑

            completionHandler (YES);

        }];

       //删除背景颜色

  deleteRowAction.backgroundColor = [UIColor colorWithHexString:@"#FFBE11"];

       //删除文字颜色设置

  [[UIButton appearanceWhenContainedInInstancesOfClasses:@[[LikeMyUsersViewController class]]] setTitleColor:[UIColor colorWithHexString:@"#0A0A0A"] forState:UIControlStateNormal];

        config = [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]];

        config.performsFirstActionWithFullSwipe = NO;

        return config;

    }else{

        return nil;

    }

}

iOS UItable view cell 左滑删除

原文:https://www.cnblogs.com/MiKiNuo/p/13829888.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!