iOS 10:UITableViewCell的删除按钮自定义高度 [英] iOS 10: UITableViewCell's delete button custom height

查看:64
本文介绍了iOS 10:UITableViewCell的删除按钮自定义高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用自定义UITableViewCell,尝试更改tableViewCell的删除"按钮的高度.我已经尝试了SO上所有可用的解决方案.

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.

每个人都提到在customTableViewCell类中,我们需要重写 layoutSubviews 方法并遍历 self.subViews 来找到一个子视图,该子视图应等于 UITableViewCellDeleteConfirmationView 或其他iOS版本中的 UITableViewCellDeleteConfirmationControl ,因此我使用了以下代码:

Everyone has mentioned that in customTableViewCell class we need to override layoutSubviews method and iterate over self.subViews to find a subView which should be equal to UITableViewCellDeleteConfirmationView or in other iOS versions it is UITableViewCellDeleteConfirmationControl so I have used following code:

- (void)layoutSubviews
{
    [super layoutSubviews];

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:0.0f];

    for (UIView *subView in self.subviews) {
        NSLog(@"subview: %@", self.subviews);
        if([NSStringFromClass([subView class]) rangeOfString:@"Delete"].location != NSNotFound) {
            CGRect newFrame = subView.frame;
            newFrame.size.height = 87;
            subView.frame = newFrame;
        }
    }

    [UIView commitAnimations];
}

但是 self.subView 只有两个视图,即

  • UITableViewCellContentView
  • UITableViewCellSeparatorView

如何在iOS 10+中获取tableViewCell的删除按钮视图?

How to get tableViewCell's delete button view in iOS 10+?

这是我的视图层次结构:

Here is my view hierarchy :

推荐答案

适用于所有遇到相同问题的人.

For anybody who is struggling with the same problem.

在UITableView的 iOS10 + 视图层次结构中,删除按钮已更改.现在,它位于UITableView-UISwipeActionPullView- UISwipeActionStandardButton

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

因此,现在需要代替迭代自定义UITableViewCell的 layoutSubviews 方法,而需要迭代UITableView子视图以获得UISwipeActionStandardButton.我发现tableView的 willBeginEditingRowAtIndexPath 委托是适当的地方,

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;
            }
        }
    }
}

这篇关于iOS 10:UITableViewCell的删除按钮自定义高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆