iOS TableView 滑动 UIContextualAction 无法获得正确的图像 [英] iOS TableView swipe UIContextualAction can not get a right image

查看:78
本文介绍了iOS TableView 滑动 UIContextualAction 无法获得正确的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在单元格的左滑动中设置图像,有代码,但不起作用.

- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {if (@available (iOS 11, *)) {UIContextualAction *deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {if (self.dataArray.count > indexPath.row) {[self.dataArray removeObjectAtIndex:indexPath.row];[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];}完成处理程序(是);}];deleteAction.backgroundColor = [UIColor blueColor];UIContextualAction *backAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:nil handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {//不做任何事[tableView setEditing:NO 动画:YES];完成处理程序(是);}];backAction.image = [UIImage imageNamed:@"public_system_success"];UISwipeActionsConfiguration *configuration = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction, backAction]];返回配置;}返回零;

}

我得到了这个

I want to set a image in the left swipe of cell, there is the code, but It doesn't work.

- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
if (@available (iOS 11, *)) {
    UIContextualAction *deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
        if (self.dataArray.count > indexPath.row) {
            [self.dataArray removeObjectAtIndex:indexPath.row];
            [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
        }

        completionHandler(YES);
    }];

    deleteAction.backgroundColor = [UIColor blueColor];

    UIContextualAction *backAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:nil handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
        // 不做任何事
        [tableView setEditing:NO animated:YES];
        completionHandler(YES);
    }];
    backAction.image = [UIImage imageNamed:@"public_system_success"];

    UISwipeActionsConfiguration *configuration = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction, backAction]];

    return configuration;
}

return nil;

}

I got this left swipe menu

In fact the image is the same with cell image in the left. What's wrong?

解决方案

Use transparent back for the checkmark, because UIContextualAction renders images as templates, so any filled area of the image will appear white.

This should be your image:

这篇关于iOS TableView 滑动 UIContextualAction 无法获得正确的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆