问题描述
我刚刚在iOS8上遇到过这个新API。但是,如果可以使用图像而不是文本并允许左右滑动,我无法找到任何解决方案?这有可能吗?我发现的唯一实现是:
I've just come across this new API on iOS8. I cannot however find any solution on if it is possible to use images instead of text and to allow left and right swipe? Is this even possible? The only implementation I've found is this:
- (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];
}
推荐答案
不,我不是认为可以进行正确的滑动(无论如何都要使用UITableViewCell)。但是,您可以使用colorWithPatternImage:设置其背景颜色,为按钮使用图像。按钮的宽度似乎取决于标题的长度,因此如果您想更改宽度(并且没有任何可见的标题),请使用包含所需空格的标题。
No, I don't think it's possible to have a right swipe (with a UITableViewCell, anyway). However, you can use an image for the button by setting its background color using colorWithPatternImage:. The width of the button seems to be determined by the length of the title, so if you want to change the width (and not have any visible title), use a title that consists of as many spaces as you need.
这篇关于iOS 8 UITableViewRowAction:向左滑动,图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!