You can use Autolayout and Xibs to create a footer view. But you have to put your custom view to the container view, that you assign to tableFooterView. If you use Autolayout and load Header or Footer View from xib, you should add constraints.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
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) } |