Skip to content

Instantly share code, notes, and snippets.

@fredriccliver
Created April 2, 2021 08:57
Show Gist options
  • Save fredriccliver/28fcb9a826fccefe5b0e50c6e617e7d7 to your computer and use it in GitHub Desktop.
Save fredriccliver/28fcb9a826fccefe5b0e50c6e617e7d7 to your computer and use it in GitHub Desktop.
extension UIViewController {
func resizeHeaderView(tableView:UITableView) {
guard let headerView = tableView.tableHeaderView else {
return
}
headerView.setNeedsLayout()
headerView.layoutIfNeeded()
tableView.sectionHeaderHeight = UITableView.automaticDimension
let size = headerView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
if headerView.frame.size.height != size.height {
headerView.frame.size.height = size.height
tableView.tableHeaderView = headerView
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment