I have a UITableView
, I'm adding tableFooterView
loaded from a xib.
var footer = NSBundle.mainBundle().loadNibNamed("AFooterView", owner: self, options: nil).first as! AFooterView
self.tableView.tableFooterView = footer
This works fine, but I need to be able to set the height for this footer. The xib only has a UIImageView
centered vertically and horizontally so it will adapt whatever the height of the view is.
I have no clue how to do this with AutoLayout
? What would be the right path to follow?
I'm sorry for the confusion, here's the updated answer:
I know you can do this by setting the frame height, but it might also work with auto layout just by re-assigning the footer view after your imageView has finished loading.
// either let auto layout calculate the frame, or set the frame yourself
// I set the width to an arbitrary size but it doesn't seem to matter,
// it will automatically be adjusted by the tableview when you assign it
CGFloat width = 100;
CGFloat height = 500;
footerView.frame = CGRectMake(0, 0, width, height);
// this is the "trick": re-assign the footerView after its size has been updated
// so that the tableView will show it correctly
tableView.tableFooterView = footerView;
For more information, see Resizing a UITableView’s tableHeaderView
The original answer talked about section footers, not table view footers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With