priore

TableView HeaderView autoresize

Mar 15th, 2018
83
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     override func viewDidLayoutSubviews() {
  2.         super.viewDidLayoutSubviews()
  3.        
  4.         // resize header view
  5.         if let headerView = tableView.tableHeaderView {
  6.             let size = headerView.systemLayoutSizeFitting(UILayoutFittingCompressedSize)
  7.             if headerView.frame.size.height != size.height {
  8.                 headerView.frame.size.height = size.height
  9.                 tableView.tableHeaderView = headerView
  10.                 tableView.layoutIfNeeded()
  11.             }
  12.         }
  13.     }
RAW Paste Data