7

Is there a way to alter the frame of the "swipe" [DELETE] button used on UITableViewCells? Currently its centred vertically within the cell, but if possible I would like to move it down to the cyan guide show.

enter image description here

Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
fuzzygoat
  • 26,573
  • 48
  • 165
  • 294

3 Answers3

15

If you are looking for a strongly true way to solve this problem then you should to subclass of UITableViewCell and override the all state handling methods for correct drawing your own delete button (do not call super in those methods). But there is another easy way:

@implementation CustomCell
- (void)layoutSubviews {
       [super layoutSubviews];
       if (self.showingDeleteConfirmation) {
             if ([self.subviews count] < 4) return;
             UIView *delBtn = [self.subviews objectAtIndex:3];
             delBtn.frame = CGRectOffset(delBtn.frame, 0, 10);
       }
}
@end
Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
UIBuilder
  • 1,333
  • 12
  • 15
  • 8
    `[self.subviews objectAtIndex:3]` is bound to break sooner or later. Overriding state handling and drawing custom delete button is much better idea. – Filip Radelic Aug 09 '11 at 21:16
  • yep, if we use array we should check its boundary every time before get access to items by index. – UIBuilder Aug 09 '11 at 21:24
  • That really solved my problem. But I have a question. When the Delete button appears, it seems to be moving from original position to the new position I just set which looks weird. How can we make the Delete button to appear from same position where we have set the origin for it. – Nitish Feb 10 '12 at 04:39
  • @Nitish, You need to implement your own Cell class by subclassing UITableViewCell. You can configure it from a xib and manually show or hide your delete button. – UIBuilder Feb 10 '12 at 15:38
  • As @FilipRadelic suggestion here is another example: http://stackoverflow.com/a/19412487/1721946 – Lunf Nov 19 '13 at 17:18
0

Instead of didTransitionToState:,

How about using the -(void)willTransitionToState: and setting the frame of the editingAccessoryView?

- (void)willTransitionToState:(UITableViewCellStateMask)state
{
    if (state == UITableViewCellEditingStyleDelete) 
    {

        NSInteger num = 10;

        UIView.frame = CGRectMake(UIView.frame.origin.x,UIView.frame.origin.y - num,
        UIView.size.width,UIView.size.height);
    }
}
Parth Patel
  • 1,250
  • 1
  • 13
  • 21
tacos_tacos_tacos
  • 10,277
  • 11
  • 73
  • 126
-2

Try changing the frame for Accessory View

the.evangelist
  • 488
  • 5
  • 18
  • 1
    Can you expand on that a little? I was looking to use didTransitionToState: in my UITableViewCell subclass, but I am not having any luck setting the accessoryView frame. – fuzzygoat Jul 28 '11 at 18:55