默认UITableViewCellStyleSubtitle字体大小?
实际的字体大小取决于用户在设置设置 - >通用 - > TextSize。通常情况下,你不应该使用固定的字体大小,而应该使用类似:
[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]
显然取决于你所需要的东西。无论如何,如果你创建一个UITableViewCell
风格UITableViewCellStyleSubtitle
,然后cell.text的字体是相同的对象
[UIFont preferredFontForTextStyle: UIFontTextStyleBody]
和cell.detailTextLabel的字体相同的对象
[UIFont preferredFontForTextStyle: UIFontTextStyleCaption1].
你使用以“Body”,“Subheadline”,“Footnote”,“Caption1”,“Caption2”结尾的常量,从最大到最小的字体获得字体,因此,如果您希望稍小或更大的文本,您就知道该使用什么。 “标题”与“正文”大小相同,但大胆。
最好在运行时创建一个单元格,并从中获取字体。
你可以随时在代码中为这些标签设置任何字体,所以如果你想要一些保证的固定值,你最好这样做,因为尺寸值可能因许多因素(单元格的样式,sdk版本,操作系统版本等)而异。
我模拟器上测试了4.2版本的SDK,并得到如下结果(没有额外的性能设置电池):
-
UITableViewCellStyleSubtitle:
为textLabel:黑体加粗,大小: labelFontSize + 1(18像素)
detailsLabel:黑体,尺寸:systemFontSize(14像素) -
UITableViewCellStyleValue1:
为textLabel:黑体粗体,尺寸:labelFontSize(17像素)
detailsLabel:黑体粗体,大小:systemFontSize + 1(15像素) -
UITableViewCellStyleValue2:
为textLabel :Helvetica Bold,尺寸:smallSystemFontSize(12 px)
细节标签:Helvetica,尺寸:labelFontSize(17 px)
当我在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文本字体:FONT-FAMILY: “黑体”; font-weight:bold; font-style:normal; font-size:12px
cellStyleValue2 detail font:font-family:“Helvetica”; font-weight:bold; font-style:normal;字体大小:15像素
由于这些参数明显变化,记录的字体对象是知道没有猜测工作好办法...
你是怎么得到这个的?我试着记录下来,并得到无用的字体大小信息。 – Moshe 2012-02-05 18:52:37
@Moshe,坦率地说,我只是玩了不同的价值观,并将它们与默认值进行了比较 - 所以没有100%保证这些值是准确的。 – Vladimir 2012-02-05 19:16:40