美文网首页
按钮左滑删除自定义按钮

按钮左滑删除自定义按钮

作者: Fade1992 | 来源:发表于2020-05-06 09:46 被阅读0次

做一个自定义的左滑删除按钮 带图片的 找了好久的资料就这个可以的记录一下

image.png

加一下这个代理就可以了

- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)){
    //删除
    if (@available(iOS 11.0, *)) {
        UIContextualAction *delete = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
            [self.mutArr removeObjectAtIndex:indexPath.row];
            [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];

            completionHandler (YES);
        }];
    delete.image = [UIImage imageNamed:@"money_pop_icon"];//这里还可以设置图片
    delete.backgroundColor = HEX(0xF3F3F3);
    UISwipeActionsConfiguration *config = [UISwipeActionsConfiguration configurationWithActions:@[delete]];
    return config;
    } else {
        return nil;
        // Fallback on earlier versions
    }
}

相关文章

网友评论

      本文标题:按钮左滑删除自定义按钮

      本文链接:https://www.haomeiwen.com/subject/sirightx.html