Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default UITableViewCellStyleSubtitle font size?

Tags:

What is the default font size of textLabel and detailTextLabel?

like image 750
Rui Lopes Avatar asked Jan 23 '11 17:01

Rui Lopes


2 Answers

You can always set any font to those labels in code so if you want some guaranteed fixed values you'd better do that as size values may vary depending on many factors (cell's style, sdk version, os version etc).

I've tested on simulator with 4.2 SDK version and got following results (no extra properties were set for cells):

  1. UITableViewCellStyleSubtitle:

    textLabel: Helvetica Bold, size: labelFontSize+1 (18 px)
    detailsLabel: Helvetica, size: systemFontSize (14 px)

  2. UITableViewCellStyleValue1:

    textLabel: Helvetica Bold, size: labelFontSize (17 px)
    detailsLabel: Helvetica Bold, size: systemFontSize+1 (15 px)

  3. UITableViewCellStyleValue2:

    textLabel: Helvetica Bold, size: smallSystemFontSize (12 px)
    detailsLabel: Helvetica, size: labelFontSize (17 px)

like image 116
Vladimir Avatar answered Nov 22 '22 04:11

Vladimir


The actual font size depends on the user's settings in Settings -> General -> TextSize. Normally, you shouldn't use a fixed font size, but should use something like:

[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline] 

obviously depending on what you need. Anyway, if you create a UITableViewCell with style UITableViewCellStyleSubtitle, then the font of cell.text is the same object as

[UIFont preferredFontForTextStyle: UIFontTextStyleBody] 

and the font of cell.detailTextLabel is the same object as

[UIFont preferredFontForTextStyle: UIFontTextStyleCaption1].  

You get fonts from largest to smallest using the constants ending in "Body", "Subheadline", "Footnote", "Caption1", "Caption2" so you know what to use if you want slightly smaller or bigger text. "Headline" is same size as "Body" but bold.

It's probably best to just create a cell at runtime and get the fonts from it.

like image 20
gnasher729 Avatar answered Nov 22 '22 04:11

gnasher729