What is the default height of UITableViewCell?

IosIphoneUitableview

Ios Problem Overview


I thought this information would have been easier to find :-)

What is the default height of a UITableViewCell? It looks like 44 pixels, but I'd prefer to be sure.

Ios Solutions


Solution 1 - Ios

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.)

Solution 2 - Ios

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.

Solution 3 - Ios

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.

Solution 4 - Ios

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.

Solution 5 - Ios

In Swift 4 and Swift 5 simply use:

UITableView.automaticDimension

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

Solution 6 - Ios

"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!

Solution 7 - Ios

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.

Solution 8 - Ios

On iOS 12 the default height on iPhone X like devices (X, XS, XS Max, XR) is 49pt.

Other devices on iOS 12 still have 44pt as default. It's a subtle difference, but it feels like a good improvement in direct comparison.

If you won't believe me, measure for yourself in this screenshot (don't forget to divide by 3)... ;)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRobView Question on Stackoverflow
Solution 1 - IosMarcoView Answer on Stackoverflow
Solution 2 - Iossam_smithView Answer on Stackoverflow
Solution 3 - Iosma11hew28View Answer on Stackoverflow
Solution 4 - IosbrainjamView Answer on Stackoverflow
Solution 5 - IosDan BrayView Answer on Stackoverflow
Solution 6 - IosfrankView Answer on Stackoverflow
Solution 7 - IosZiltoidView Answer on Stackoverflow
Solution 8 - IosheyfrankView Answer on Stackoverflow