2009-09-08 77 views
3

我正在使用帶有小標題的表格單元格,並希望我的文字變得更大一些。大小UITableViewCell與UITableViewCellStyleSubtitle重疊

cell.textLabel.font = [UIFont boldSystemFontOfSize:30]; 

和細胞高度heightForRowAtIndexPath更改爲80我碰上了textLabel是成功的一半由detailTextLabel隱藏的問題。我很驚訝這個處理不當。我試圖改變標籤的邊界,但它沒有效果。我該如何設置「位置」,「內容矩形」或其他任何有大的textLabel和小的detailTextLabel

+0

具有完全相同的問題。也許這可以幫助: http://stackoverflow.com/questions/1311935/nsstring-is-cut-off-prematurely-in-a-uitableviewcell-in-3-0-but-looks-fine-in-3 – mentat 2010-01-12 14:22:41

回答

1

我相信這是在更高版本的iOS中修復的。但是,如果您確實想爲「字幕」或其他樣式的單元格提供自定義佈局(爲了充分利用某些佈局功能(例如定位圖像/附件等)),可以通過對它們進行子類化來輕鬆完成。在子類的init與所需的風格超並重寫layoutSubviews如下:

- (void)layoutSubviews 
{ 
    [super layoutSubviews]; 
    // Set the content view frame 
    CGRect cvFrame = self.contentView.frame; 
    cvFrame.origin.y = 0; 
    cvFrame.size.height = 80; 
    self.contentView.frame = cvFrame; 
    // Set the text label position 
    CGRect tlFrame = self.textLabel.frame; 
    tlFrame.origin.y = 2; 
    self.textLabel.frame = tlFrame; 
    // Set the detail label position 
    CGRect dtlFrame = self.detailTextLabel.frame; 
    dtlFrame.origin.y = 2 + tlFrame.size.height + 2; 
    self.detailTextLabel.frame = dtlFrame; 
} 

這樣,您就可以使用已經在[超級layoutSubviews]中設定的幀值,並設定自己的。如果您將更多視圖添加到單元格中,則可以在此處設置其位置。