iOS 10: UITableViewCell's delete button custom height

前端 未结 4 710
既然无缘
既然无缘 2021-01-15 04:44

Using custom UITableViewCell, I\'m trying to change the height of tableViewCell\'s delete button. I\'ve tried all the solutions available here on SO.

Everyone has me

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-15 05:27

    For anybody who is struggling with the same problem.

    In iOS10+ view hierarchy for UITableView's delete button has been changed. Now it comes under UITableView - UISwipeActionPullView - UISwipeActionStandardButton

    So now instead of overriding custom UITableViewCell's layoutSubviews method, we need to iterate UITableView subviews in order to get UISwipeActionStandardButton. And I found tableView's willBeginEditingRowAtIndexPath delegate as an appropriate place,

    - (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
    {
        for (UIView *subview in tableView.subviews) {
            if ([NSStringFromClass([subview class]) isEqualToString:@"UISwipeActionPullView"]) {
                if ([NSStringFromClass([subview.subviews[0] class]) isEqualToString:@"UISwipeActionStandardButton"]) {
                    CGRect newFrame = subview.subviews[0].frame;
                    newFrame.size.height = 72;
                    subview.subviews[0].frame = newFrame;
    
                    //Other changes on this view can also be applied like
                    subview.subviews[0].backgroundColor = [UIColor redColor];
                    subview.subviews[0].layer.cornerRadius = 12;
                    subview.subviews[0].layer.masksToBounds = YES;
                }
            }
        }
    }
    

提交回复
热议问题