默认UITableViewCellStyleSubtitle字体大小?

Rui*_*pes 23 iphone uitableview

textLabel和detailTextLabel的默认字体大小是多少?

Vla*_*mir 51

您总是可以在代码中为这些标签设置任何字体,因此如果您想要一些保证固定值,最好这样做,因为大小值可能会因许多因素(单元格样式,sdk版本,操作系统版本等)而有所不同.

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

  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)


gna*_*729 14

实际字体大小取决于用户在"设置" - >"常规" - >"TextSize"中的设置.通常,您不应使用固定的字体大小,但应使用以下内容:

[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]
Run Code Online (Sandbox Code Playgroud)

显然取决于你需要什么.无论如何,如果你创建一个UITableViewCellwith style UITableViewCellStyleSubtitle,那么cell.text的字体就是同一个对象

[UIFont preferredFontForTextStyle: UIFontTextStyleBody]
Run Code Online (Sandbox Code Playgroud)

和cell.detailTextLabel的字体是相同的对象

[UIFont preferredFontForTextStyle: UIFontTextStyleCaption1]. 
Run Code Online (Sandbox Code Playgroud)

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

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


ste*_*hen 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);
Run Code Online (Sandbox Code Playgroud)

我知道了:

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

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