SHARE
TWEET

Untitled

a guest Oct 12th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Adjust size of table header view
  2. extension UITableViewController {
  3.     var tableHeaderView: UIView {
  4.         return self.customHeaderView
  5.     }
  6.  
  7.     var tableFooterView: UIView {
  8.         return self.customFooterView
  9.     }
  10.  
  11.     override func viewDidLayoutSubviews() {
  12.         super.viewDidLayoutSubviews()
  13.  
  14.         self.adjustSizeOfTableHeaderView()
  15.         self.adjustSizeOfTableFooterView()
  16.     }
  17.  
  18.     func adjustSizeOfTableHeaderView() {
  19.         self.tableHeaderView.layoutIfNeeded()
  20.         let size = self.tableHeaderView.systemLayoutSizeFitting(UILayoutFittingCompressedSize)
  21.         self.tableView.tableHeaderView?.frame.size = size
  22.         self.tableView.tableHeaderView = self.tableHeaderView
  23.     }
  24.  
  25.     func adjustSizeOfTableFooterView() {
  26.         self.tableFooterView.layoutIfNeeded()
  27.         let size = self.tableFooterView.systemLayoutSizeFitting(UILayoutFittingCompressedSize)
  28.         self.tableView.tableFooterView?.frame.size = size
  29.         self.tableView.tableFooterView = self.tableFooterView
  30.     }
  31. }
RAW Paste Data
Top