UITableViewCell样式中使用的默认字体设置是什么?

时间:2011-03-02 22:55:31

标签: ios uitableview

任何人都有Apple在UITableViewCells,UILabel等中使用的默认字体设置列表? UITableViewCell中textLabel的定位信息既分组又简单。

2 个答案:

答案 0 :(得分: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 = print,但您必须将值转换为您知道的类型

无属性访问cell.frame - 使用objective-c方法[cell frame]

另外,这是一篇关于iPhone字体的4年历史但仍然有用的文章:daring fireball

答案 1 :(得分: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