Skip to content

Instantly share code, notes, and snippets.

@JasonCanCode
Last active April 18, 2021 18:45
Show Gist options
  • Save JasonCanCode/a95c72f00ae3d1709e5b8958dc6adf65 to your computer and use it in GitHub Desktop.
Save JasonCanCode/a95c72f00ae3d1709e5b8958dc6adf65 to your computer and use it in GitHub Desktop.
Dynamic Table View Header Height
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