UITableView: changing footer view's size programmatically doesn't work

后端 未结 2 1485
闹比i
闹比i 2021-02-05 06:47

My table view\'s footer is a view that shows some tweets from a user, so I do not know its height until I got the tweets, I created a FooterViewController that has

相关标签:
2条回答
  • 2021-02-05 07:14

    In order to change the frame of footer view here is the simple tweak:-

    In Swift:-

    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.5
    }
    
    
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        let footerView = UIView()
        let footerChildView = UIView(frame: CGRect(x: 60, y: 0, width: tableView.frame.width - 60, height: 0.5))
        footerChildView.backgroundColor = UIColor.darkGray
        footerView.addSubview(footerChildView)
        return footerView
    }
    
    0 讨论(0)
  • 2021-02-05 07:33
    myTable.tableFooterView = myFooterView;
    

    Re-assign your footer view to the table. The table will recognize it has a new footer and re-do whatever layout needs to occur for the proper size of the footer.

    0 讨论(0)
提交回复
热议问题