我想在单元格的左侧滑动中设置一个图像,有代码,但不起作用。
- (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;}
我得到了这个left swipe menu
实际上,该图像与左侧的细胞图像相同。怎么了?
发布于 2018-11-07 17:09:58
复选标记使用透明背面,因为UIContextualAction将图像渲染为模板,因此图像的任何填充区域都将显示为白色。
这应该是您的图像:

发布于 2018-01-31 13:51:54
检查您的图像。我认为当你滑动选中你的图片时,单元格会给你的图片加上一种色彩。试试这个..。1.进入xcode中的assets文件夹,选择您的镜像。2.转到右侧属性检查器,选择渲染为选项,然后选择原始图像。3.测试。
如果有帮助,请告诉我:-)
发布于 2020-10-16 15:29:34
将UIContextualActionStyleDestructive更改为UIContextualActionStyleNormal
https://stackoverflow.com/questions/48535245
复制相似问题