Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // For the best results, your tableHeaderView/tableFooterView should be a UITableViewHeaderFooterView with your content inside the contentView.
- let tableHeaderView = UITableViewHeaderFooterView()
- let fittingSize = CGSize(width: tableView.bounds.width - (tableView.safeAreaInsets.left + tableView.safeAreaInsets.right), height: 0)
- let size = tableHeaderView.contentView.systemLayoutSizeFitting(fittingSize, withHorizontalFittingPriority: UILayoutPriorityRequired, verticalFittingPriority: UILayoutPriorityFittingSizeLevel)
- tableHeaderView.frame = CGRect(origin: .zero, size: size)
- tableView.tableHeaderView = tableHeaderView
- // In particular, note that we call systemLayoutSizeFitting on the contentView of the UITableViewHeaderFooterView.
- // When you set this view to the tableHeaderView/tableFooterView on the table view, the table view will preserve the existing size of its frame.
- // If you need to change the size, remove the tableHeaderView/tableFooterView, set a new frame on it, then re-set it on the table view again.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement