繁体   English   中英

iOS 8 UITableViewRowAction:向左滑动,图像?

[英]iOS 8 UITableViewRowAction: Swipe Left, Images?

我刚刚在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];
}

不,我认为没有可能进行正确的滑动(无论如何都要使用UITableViewCell)。 但是,您可以使用colorWithPatternImage:设置其背景颜色,为按钮使用图像。 按钮的宽度似乎取决于标题的长度,因此如果要更改宽度(并且没有任何可见标题),请使用包含所需空格的标题。

在Swift中它将是:

deleteAction.backgroundColor = UIColor(patternImage: UIImage(named:"sample")!)

将图像添加到滑动视图时,此答案可能会有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM