Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. // For the best results, your tableHeaderView/tableFooterView should be a UITableViewHeaderFooterView with your content inside the contentView.
  2. let tableHeaderView = UITableViewHeaderFooterView()
  3.  
  4. let fittingSize = CGSize(width: tableView.bounds.width - (tableView.safeAreaInsets.left + tableView.safeAreaInsets.right), height: 0)
  5. let size = tableHeaderView.contentView.systemLayoutSizeFitting(fittingSize, withHorizontalFittingPriority: UILayoutPriorityRequired, verticalFittingPriority: UILayoutPriorityFittingSizeLevel)
  6. tableHeaderView.frame = CGRect(origin: .zero, size: size)
  7. tableView.tableHeaderView = tableHeaderView
  8.  
  9. // In particular, note that we call systemLayoutSizeFitting on the contentView of the UITableViewHeaderFooterView.
  10. // When you set this view to the tableHeaderView/tableFooterView on the table view, the table view will preserve the existing size of its frame.
  11. // 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