2011-03-02 95 views
8

任何人都有苹果在UITableViewCells,UILabel等中使用的默认字体设置列表?同样,UITableViewCell中textLabel的定位信息都是分组的,并且非常棒。UITableViewCell样式中使用的默认字体设置是什么?

+1

检查我对类似的问题的答案:http://stackoverflow.com/questions/4775107/uitableviewcellstylesubtitle-font-size/4777507#4777507。 – Vladimir 2011-03-02 23:10:30

+0

检查标签定位只需创建示例项目,并检查哪些单元格的标签框架。它们可能取决于许多因素(例如单元大小),并且可能在未来可能会发生变化,因此无论如何您都不应该依赖这些值。 – Vladimir 2011-03-02 23:13:00

+0

@Vladimir谢谢你的回答。你用来检查UIViews帧的代码是什么?你知道是否有类似的电话会告诉你字体的颜色和大小吗? – Aaronium112 2011-03-03 15:56:51

回答

12

您是否熟悉调试器?它知道所有。要访问布局,请在gdb中尝试以下内容。

我设置的断点在- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath显示单元右侧前

被称为(注:有一个背景图像在我的细胞)

(gdb) po cell 
<UITableViewCell: 0x59e9920; frame = (0 66; 320 44); text = '396 Studio'; autoresize = W; layer = <CALayer: 0x59e9a00>> 

(gdb) po [cell subviews] 
<__NSArrayM 0x4eaf730>(
<UIImageView: 0x59ea660; frame = (0 0; 320 100); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x59ea690>>, 
<UITableViewCellContentView: 0x59e9eb0; frame = (9 0; 302 44); layer = <CALayer: 0x59ea070>> 
) 

(gdb) po [[[cell subviews] objectAtIndex:1] subviews] 
<__NSArrayM 0x4eaf700>(
<UILabel: 0x59e9170; frame = (0 0; 0 0); text = '396 Studio'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x59e91e0>>, 
<UITableViewLabel: 0x59e65c0; frame = (0 0; 0 0); text = 'Houston'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x59e6690>> 
) 


(gdb) po [0x59e9170 font] 
<UICFFont: 0x5e12610> font-family: "Helvetica"; font-weight: bold; font-style: normal; font-size: 0px 


(gdb) p (CGRect)[cell frame] 
$1 = { 
    origin = { 
    x = 0, 
    y = 66 
    }, 
    size = { 
    width = 320, 
    height = 44 
    } 
} 

po =打印对象 p =打印,但您必须将值转换为您知道的类型

无资产访问cell.frame - 使用objective-c方法[cell frame]

此外,这是一个4岁,但仍然有用的iPhone字体文章:daring fireball

+5

教一个人钓鱼... – Buzzy 2011-11-02 12:09:06

+1

这是有用的,直到调试器报告字体大小为零。在什么时候确定了*真实*字体大小? – Bill 2012-04-21 11:42:04

+1

你可以尝试继承'UITableViewCell',重写一个重要的显示方法来调用'super'并检查值,然后 – bshirley 2012-04-22 13:42:22

7

我创建了一个UITableViewCell的子类来获取这些值。我的继承人代码:

dlog(@"%@",self.detailTextLabel.font); 
    dlog(@"%@",self.detailTextLabel.bounds); 
    dlog(@"%f",self.detailTextLabel.frame.size.height); 
    dlog(@"%f",self.detailTextLabel.frame.size.width); 
    dlog(@"%f",self.detailTextLabel.frame.origin.x); 
    dlog(@"%f",self.detailTextLabel.frame.origin.y); 
    dlog(@"%@",self.detailTextLabel.textColor); 

输出:

2012-06-06 15:01:08.384 myapp[1007:f803] <mytablecell.m:(48)> <UICFFont: 0x68c8b20> font-family: "Helvetica"; font-weight: normal; font-style: normal; font-size: 14px//remember the text will shrink before hiding some with the "..." but this is default 
    2012-06-06 15:01:08.387 myapp[1007:f803] <mytablecell.m:(49)> (null) 
    2012-06-06 15:01:08.389 myapp[1007:f803] <mytablecell.m:(50)> 18.000000 
    2012-06-06 15:01:08.391 myapp[1007:f803] <mytablecell.m:(51)> 280.000000//its 284 if there is no accessory view(such as the checkmark I had in there when this ran) 
    2012-06-06 15:01:08.393 myapp[1007:f803] <mytablecell.m:(52)> 10.000000 
    2012-06-06 15:01:08.396 myapp[1007:f803] <mytablecell.m:(53)> 24.000000 
    2012-06-06 15:01:08.398 myapp[1007:f803] <mytablecell.m:(54)> UIDeviceRGBColorSpace 0.5 0.5 0.5 1