简体   繁体   English

在表格视图中重新定位滑动到删除按钮

[英]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. 否,无法使用“删除”按钮进行任何更改,因为它是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 在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 . 您可以设置UIImageView的框架。

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

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