我刚刚在iOS8上遇到了这个新的API。然而,我找不到任何解决方案,如果可以使用图像而不是文本,并允许左右滑动?这有可能吗?我找到的唯一实现是这样的:
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction *moreAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Button1" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
// maybe show an action sheet with more options
[self.tableView setEditing:NO];
}];
moreAction.backgroundColor = [UIColor blueColor];
UITableViewRowAction *moreAction2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Button2" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
[self.tableView setEditing:NO];
}];
moreAction2.backgroundColor = [UIColor blueColor];
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}];
return @[deleteAction, moreAction, moreAction2];
}发布于 2014-09-28 06:44:05
不,我不认为有可能有一个右滑动(至少用UITableViewCell )。但是,您可以通过使用colorWithPatternImage:设置按钮的背景色来使用该按钮的图像。按钮的宽度似乎是由标题的长度决定的,因此,如果您想要更改宽度(并且没有任何可见的标题),请使用一个由所需空格组成的标题。
发布于 2014-11-06 05:09:53
在Swift中,它将是:
deleteAction.backgroundColor = UIColor(patternImage: UIImage(named:"sample")!)发布于 2018-03-22 15:39:17
当您向滑动视图添加图像时,此answer可能会有所帮助。
https://stackoverflow.com/questions/26079310
复制相似问题