Skip to content

Instantly share code, notes, and snippets.

@jwthanh
Created December 5, 2015 11:42
Show Gist options
  • Save jwthanh/67775d401e054ac046a3 to your computer and use it in GitHub Desktop.
Save jwthanh/67775d401e054ac046a3 to your computer and use it in GitHub Desktop.
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
// Dynamic sizing for the header view
if let headerView = tableView.tableHeaderView {
let height = headerView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize).height
var headerFrame = headerView.frame
// If we don't have this check, viewDidLayoutSubviews() will get
// repeatedly, causing the app to hang.
if height != headerFrame.size.height {
headerFrame.size.height = height
headerView.frame = headerFrame
tableView.tableHeaderView = headerView
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment