Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default height of UITableViewCell?

People also ask

What is the default cell height?

The default size of an Excel column is 8.43, which correlates to 64 pixels. Rows can have a maximum height of 409. This number represents how many one-seventy seconds of an inch the row can hold.

How do I change cell height in Swift?

To change the height of tableView cell in ios dynamically, i.e resizing the cell according to the content available, we'll need to make use of automatic dimension property.


It's 44 pixels. Definitely. I'll never forget that number.

44px is also the default height for UIToolbar and UINavigationBar. (Both switch to 32px when autorotated to landscape orientation.)


If you want the default dimension on any device you can use: UITableViewAutomaticDimension

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

    return UITableViewAutomaticDimension;
}

Although 44 pixels is currently the default this is a useful method if your app relies on having the default value set.


When style = UITableViewStyleGrouped, the default height of the top & bottom cells is actually 45.0f (not 44.0f). And, if the grouped table is only one row the cell height will be 46.0f.


If you want to calculate this on the fly, just allocate a dummy table cell and read off its height

UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
int height = cell.frame.size.height ;

This way you defend against changes in future versions of iOS, although I suppose that is unlikely.


In Swift 4 and Swift 5 simply use:

UITableView.automaticDimension

Using 44px won't suffice because it will vary with different screen pixel densities.


"When style = UITableViewStyleGrouped, the default height of the top & bottom cells is actually 45.0f (not 44.0f). And, if the grouped table is only one row the cell height will be 46.0f." It's wrong!! 44.0f in fact! I just test it!


That sounds about right. But to be sure you could load up Interface builder, put in a UITableViewCell into the project then check the size properties in the Inspector window. I do not have my MacBook with me right now so I cannot check. But if you don't get a better answer from someone, that is how you can check for yourself.