Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the height to a tableFooterView loaded from a xib

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?

like image 538
Andres Avatar asked Jun 22 '15 21:06

Andres


1 Answers

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

like image 55
Velociround Avatar answered Oct 17 '22 00:10

Velociround