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;
}
网友评论