热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

iOS10:UITableViewCell的删除按钮自定义高度

如何解决《iOS10:UITableViewCell的删除按钮自定义高度》经验,为你挑选了1个好方法。

使用自定义UITableViewCell,我试图更改tableViewCell的“删除”按钮的高度。我已经尝试过此处提供的所有解决方案。

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

- (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的删除按钮视图?

编辑

这是我的视图层次结构:



1> Muhammad Uma..:

对于任何正在努力解决相同问题的人。

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

因此,现在需要代替layoutSubviews迭代自定义UITableViewCell的方法,而需要迭代UITableView子视图才能获取UISwipeActionStandardButton。我发现tableView的willBeginEditingRowAtIndexPath委托是合适的地方,

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


推荐阅读
author-avatar
az旺成电料
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有