动态更改 UITableView Footer 高度

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

添加新评论

电子邮件地址不会被公开,评论内容可能需要管理员审核后显示。