首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS 8 UITableViewRowAction:向左滑动,图片?

iOS 8 UITableViewRowAction:向左滑动,图片?
EN

Stack Overflow用户
提问于 2014-09-28 05:15:52
回答 3查看 13K关注 0票数 9

我刚刚在iOS8上遇到了这个新的API。然而,我找不到任何解决方案,如果可以使用图像而不是文本,并允许左右滑动?这有可能吗?我找到的唯一实现是这样的:

代码语言:javascript
复制
- (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];
}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-09-28 06:44:05

不,我不认为有可能有一个右滑动(至少用UITableViewCell )。但是,您可以通过使用colorWithPatternImage:设置按钮的背景色来使用该按钮的图像。按钮的宽度似乎是由标题的长度决定的,因此,如果您想要更改宽度(并且没有任何可见的标题),请使用一个由所需空格组成的标题。

票数 15
EN

Stack Overflow用户

发布于 2014-11-06 05:09:53

在Swift中,它将是:

代码语言:javascript
复制
deleteAction.backgroundColor = UIColor(patternImage: UIImage(named:"sample")!)
票数 5
EN

Stack Overflow用户

发布于 2018-03-22 15:39:17

当您向滑动视图添加图像时,此answer可能会有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26079310

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档