我想在左边的单元格中设置一个图像,有代码,但它不起作用。
- (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
实际上,图像与左侧的细胞图像相同。怎么了?
答案 0 :(得分:0)
检查你的形象。我认为当您滑动选择它们时,单元格会对图像应用色调。试试这个.. 1.转到xcode中的assets文件夹并选择您的图像。 2.转到右侧的Property Inspector,然后选择"渲染为"选项并选择原始图像。 3.测试。
如果有帮助,请告诉我: - )
答案 1 :(得分:0)
答案 2 :(得分:0)
将UIContextualActionStyleDestructive
更改为UIContextualActionStyleNormal