默认UITableViewCellStyleSubtitle字体大小?

时间:2011-01-23 17:10:59

标签: iphone uitableview

textLabel和detailTextLabel的默认字体大小是什么?

3 个答案:

答案 0 :(得分:51)

你总是可以在代码中为这些标签设置任何字体,所以如果你想要一些保证的固定值你最好这样做,因为尺寸值可能会因许多因素(单元格的样式,sdk版本,os版本等)而有所不同。

我已经在4.2 SDK版本的模拟器上进行了测试并获得了以下结果(没有为单元格设置额外的属性):

  1. <强> UITableViewCellStyleSubtitle

    textLabel:Helvetica Bold,尺寸:labelFontSize + 1(18 px)
     detailsLabel:Helvetica,大小:systemFontSize(14 px)

  2. <强> UITableViewCellStyleValue1

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

  3. <强> UITableViewCellStyleValue2

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

答案 1 :(得分:13)

实际字体大小取决于用户在设置中的设置 - &gt;一般 - &gt;字体大小。通常,您不应使用固定的字体大小,但应使用以下内容:

[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]

显然取决于你需要什么。无论如何,如果你创建一个样式为UITableViewCell的{​​{1}},那么cell.text的字体与

是同一个对象
UITableViewCellStyleSubtitle

,cell.detailTextLabel的字体与

是同一个对象
[UIFont preferredFontForTextStyle: UIFontTextStyleBody]

使用以“Body”,“Subheadline”,“Footnote”,“Caption1”,“Caption2”结尾的常量,您可以获得从大到小的字体,这样您就可以知道如果您想要稍微更小或更大的文本,可以使用什么。 “标题”与“身体”大小相同但是大胆。

最好只在运行时创建一个单元格并从中获取字体。

答案 2 :(得分:5)

当我在iPad 5.0模拟器上运行时:

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

我明白了:

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

由于这些参数明显不同,因此记录字体对象是一种很好的方法,无需猜测即可...