If you use Autolayout
and load Header
or Footer
View
from xib
, you should add constraints
:
func setupTableFooterView() {
// Create your footer view from XIB and set constraints (in my case it is historyToolBarView of class HistoryToolBarView)
let view = Bundle.main.loadNibNamed("HistoryToolBarView", owner: self, options: nil)?.first
historyToolBarView = view as! HistoryToolBarView
historyToolBarView.translatesAutoresizingMaskIntoConstraints = false
historyToolBarView.addConstraints(
[NSLayoutConstraint.init(item: self.historyToolBarView,
attribute: .height,
relatedBy: .equal,
toItem: nil,
attribute: .notAnAttribute,
multiplier: 1.0,
constant: 60),
NSLayoutConstraint.init(item: self.historyToolBarView,
attribute: .width,
relatedBy: .equal,
toItem: nil,
attribute: .notAnAttribute,
multiplier: 1.0,
constant: UIScreen.main.bounds.size.width)])
// Create a container of your footer view called footerView and set it as a tableFooterView
let footerView = UIView(frame: CGRect.init(x: 0, y: 0, width: tableView.frame.width, height: 60))
footerView.backgroundColor = UIColor.green
tableView.tableFooterView = footerView
// Add your footer view to the container
footerView.addSubview(historyToolBarView)
}