0

How can I change the image for the delete button in a table view cell?

I mean the red circle button on the left side:

jscs
  • 63,694
  • 13
  • 151
  • 195
  • Refer this http://stackoverflow.com/questions/20290766/change-the-color-of-default-red-color-delete-button-in-uitableviewcell-when-swip – Santosh Jul 07 '16 at 23:20

1 Answers1

2

Override the following in your UITableViewCell subclass:

- (void)willTransitionToState:(UITableViewCellStateMask)state
{
    [super willTransitionToState:state];
    if(state == UITableViewCellStateShowingEditControlMask)
    {
        for (UIView *v in self.subviews) {
            if ([NSStringFromClass([v class]) isEqualToString:@"UITableViewCellEditControl"]) {
                UIImageView *customButton = [[UIImageView alloc]initWithFrame:v.bounds];
                [customButton setImage:[UIImage imageNamed:@"delete.png"]];
                [v addSubview:customButton];
                [v bringSubviewToFront:customButton];
            }
        }
    }
}

You can play with the subviews and the states to achieve your preferred result.

jackal
  • 1,143
  • 17
  • 32