开发者

Default UITableViewCellStyleSubtitle font size?

What is the default font size of textLabel and 开发者_Go百科detailTextLabel?


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)


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.


When I run this on the iPad 5.0 simulator:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] 
             initWithStyle:UITableViewCellStyleValue2
             reuseIdentifier:CellIdentifier] autorelease];

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
//set text to get font size > 0

NSLog(@"cellStyleValue2 text font: %@\n", cell.textLabel.font);
NSLog(@"cellStyleValue2 detail font: %@\n", cell.detailTextLabel.font);

I see:

cellStyleValue2 text font: font-family: "Helvetica"; font-weight: bold; font-style: normal; font-size: 12px

cellStyleValue2 detail font: font-family: "Helvetica"; font-weight: bold; font-style: normal; font-size: 15px

Since these parameters apparently vary, logging the font objects is good way to know without the guess work...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜