美文网首页
iOS 滑动删除 自定义图片

iOS 滑动删除 自定义图片

作者: ONE2 | 来源:发表于2020-09-28 17:16 被阅读0次

iOS11之后使用如下方法

- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)p  API_AVAILABLE(ios(11.0)){
    UIContextualAction *delete = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:nil handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
        completionHandler (YES);
    }];
    delete.image = [UIImage imageNamed:@"home_delete"];
    delete.backgroundColor = [UIColor whiteColor];
    UIContextualAction *share = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:nil handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
        completionHandler (YES);
    }];
    share.image = [UIImage imageNamed:@"home_share"];
    share.backgroundColor = [UIColor whiteColor];
    
    UISwipeActionsConfiguration *config = [UISwipeActionsConfiguration configurationWithActions:@[delete, share]];
    // 是否左滑到一定程度执行第一个操作
    config.performsFirstActionWithFullSwipe = NO;
    return config;
}

相关文章

网友评论

      本文标题:iOS 滑动删除 自定义图片

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