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. }