简体   繁体   中英

Reposition swipe-to-delete button in tableview

I have a tableview with custom-designed cells and thus if I add the swipe-to-delete buttons the layout is horrible. Is it possible to reposition these buttons inside the cell?

您不应该尝试这样做,也不应该更改Apple的默认视图。

NO it is not possible to made any changes with delete button because it is built-in or default functionality of Apple iOS. So better to stop fighting with it :)

Yes, you can change the button.

Maybe this code can help you. Write the following code in yourCustomCell.m

- (void)willTransitionToState:(UITableViewCellStateMask)state 
  {
      [super willTransitionToState:state];
      if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) 
      {
          for (UIView *subview in self.subviews) 
          {
              if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) 
              {
                  UIImageView *deleteBtn = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 64, 33)];
                  [deleteBtn setImage:[UIImage imageNamed:<yourCustomImage.png>]];
                  [[subview.subviews objectAtIndex:0] addSubview: deleteBtn];
          }
       }
    }
 }

You can set the frame of UIImageView .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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