Last active
April 18, 2021 18:45
-
-
Save JasonCanCode/a95c72f00ae3d1709e5b8958dc6adf65 to your computer and use it in GitHub Desktop.
Dynamic Table View Header Height
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() | |
sizeTableViewHeaderToFit() | |
} | |
// MARK: - Dynamic Header Height | |
func sizeTableViewHeaderToFit() { | |
guard let headerView = tableView.tableHeaderView else { | |
return | |
} | |
let size = headerView.systemLayoutSizeFitting(UIView.layoutFittingExpandedSize) | |
if headerView.frame.size.height != size.height { | |
headerView.frame.size.height = size.height | |
tableView.tableHeaderView = headerView | |
tableView.layoutIfNeeded() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment