2011-03-02 61 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