Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 8 UITableViewRowAction: Swipe Left, Images?

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];
}
like image 713
MichiZH Avatar asked Sep 27 '14 21:09

MichiZH


2 Answers

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.

like image 165
rdelmar Avatar answered Oct 21 '22 08:10

rdelmar


in Swift it would be:

deleteAction.backgroundColor = UIColor(patternImage: UIImage(named:"sample")!)
like image 5
theHellyar Avatar answered Oct 21 '22 08:10

theHellyar