Created
February 24, 2019 14:58
-
-
Save hossamghareeb/904a1f903fd970fec6d6fe20562940ac to your computer and use it in GitHub Desktop.
Dynamic UITable header view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func viewDidLayoutSubviews() { | |
super.viewDidLayoutSubviews() | |
updateTableViewHeaderHeight() | |
} | |
private func updateTableViewHeaderHeight() { | |
guard let headerView = tableView.tableHeaderView else { return } | |
/// Get the size that should meet the constraints | |
let size = headerView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize) | |
guard size.height != headerView.frame.height else { return } | |
headerView.frame.size.height = size.height | |
tableView.tableHeaderView = headerView | |
tableView.layoutIfNeeded() // make sure to proper layout cells for the new header size. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment