Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewCells to be in center of UITableView

I want that my 4 cells will be in the center of my UITableView. Can't scroll the UITableView. That there will be the same height above the first cell and below the last cell.

thanks

like image 924
Shay Avatar asked Dec 06 '25 17:12

Shay


2 Answers

Create an empty UIView, set its height to the height you require, and then set that view as the tableHeaderView.

You can do it all from Interface Builder, even.

If you want to calculate what height is required:

CGFloat headerHeight = (tableView.size.height - tableView.rowHeight * [tableView numberOfRowsInSection:0])  / 2; 
// assuming one section, otherwise add all sections
like image 134
Aviad Ben Dov Avatar answered Dec 08 '25 06:12

Aviad Ben Dov


you need to use tableView.bounds.size.height instead of tableView.size.height and subtract the sectionHeaderHeight as well

like image 40
nzdravevski Avatar answered Dec 08 '25 08:12

nzdravevski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!