Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the height of table header in UITableView?

I have gone through Apple docs about UITableView class and delegate reference but couldn't find the way to set the table header height explicitly.

I set Table cell height using following delegate:

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 

and set section header/footer height using following delegates.

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 

Could anyone please help me to set the table header/footer height?

Thanks.

like image 724
AlienMonkeyCoder Avatar asked Apr 07 '11 12:04

AlienMonkeyCoder


People also ask

How do I change the height of a header in Swift?

Step 1: Set the section header height as UITableView. automaticDimension. Step 2: In estimated height for header delegate assign an estimated value. Step 3: In view for header delegate add a UILabel and apply constraints relative to the returning UIView.


2 Answers

Just set the frame property of the tableHeaderView.

like image 91
Roger Avatar answered Sep 19 '22 15:09

Roger


I found a nice hack. Add the below line after modifying the frame propery

self.tableView.tableHeaderView = self.tableView.tableHeaderView; 

The trick is (I think) that the UITableView is caching the height (the frame actually) when you assign the view to the tableHeaderView property. The above line just assigns the height again.

like image 28
Cristian Bica Avatar answered Sep 16 '22 15:09

Cristian Bica