美文网首页Swift开发Swift开发技巧征服iOS
动态更改UITableView Footer高度

动态更改UITableView Footer高度

作者: d2f2a0642f87 | 来源:发表于2016-03-02 23:52 被阅读1291次

override 所在UIViewController的 viewDidLayoutSubviews方法

override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        
        if let footView = tableView.tableFooterView {
        //footerContentView 是footerView的内容视图,它使用自动布局来自适应高度,然后在代码里面获取高度变更footerView 的高度
            let height = footerContentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize).height
            if height != footerView.frame.height {
                print("new height=\(height)")
                footView.frame.size.height = height
                tableView.tableFooterView = footView
            }
        }
    }

相关文章

网友评论

  • Hengry:OC怎么弄呢
    Hengry:@Locke :+1:
    Locke:- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    UIView *footerView = self.tableView.tableFooterView;
    float height = [self.tableView.tableFooterView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
    if (height != footerView.frame.size.height ) {
    footerView.frame = (CGRect){footerView.frame.origin, footerView.frame.size.height, height};
    self.tableView.tableFooterView = footerView;
    }
    }

本文标题:动态更改UITableView Footer高度

本文链接:https://www.haomeiwen.com/subject/rywnkttx.html