2011-05-31 72 views
0

我試圖在Tableview單元格中顯示標題數據但它部分顯示(...)我想在表格單元格中顯示完整標題可能會在兩行或三行中使用自定義單元格並使用標籤和集標籤屬性,但仍數據部分在tableView Cell中部分顯示標題?

titleLabel.text = aNewsInfo.title; 

顯示任何一個可以建議我克服這個概率的方式......提前

謝謝...

回答

0

也許你可以試試:

[titleLabel sizeToFit]; 

而且你需要調整單元格的高度:

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; 
0

標籤的財產需要設置

adjustsFontSizeToFitWidth 
A Boolean value indicating whether the font size should be reduced in order to fit 
the title string into the label’s bounding rectangle. 

@property(nonatomic) BOOL adjustsFontSizeToFitWidth 

而且

numberOfLines 
The maximum number of lines to use for rendering text. 

@property(nonatomic) NSInteger numberOfLines 
Discussion 
This property controls the maximum number of lines to use in order to fit the label’s text into its bounding rectangle. The default value for this property is 1. To remove any maximum limit, and use as many lines as needed, set the value of this property to 0. 

If you constrain your text using this property, any text that does not fit within the maximum number of lines and inside the bounding rectangle of the label is truncated using the appropriate line break mode. 

When the receiver is resized using the sizeToFit method, resizing takes into account the value stored in this property. For example, if this property is set to 3, the sizeToFit method resizes the receiver so that it is big enough to display three lines of text. 
+0

因爲我用自定義單元格,所以我做的事情與IB我設置屬性行至3,也可以通過拖動邊界增加標籤的大小,但現在的標題是完全隱藏只顯示三個點(...)。現在,我應該怎麼做... – user755278 2011-05-31 08:02:17

+0

您將行數設置爲0和最小字體大小。 – 2011-05-31 08:16:14

2

試試這個代碼:

myLabel.lineBreakMode = UILineBreakModeWordWrap; 
myLabel.numberOfLines = 2; // 2 lines ; 0 - dynamical number of lines 
myLabel.text = @"Lorem ipsum dolor sit\namet..."; 
+0

阿曼這將工作,但只有硬編碼文本,如 cell.textLabel.lineBreakMode = UILineBreakModeWordWrap; cell.textLabel.numberOfLines = 2; cell.textLabel.text = aNewsInfo.title; 但在 titleLabel.lineBreakMode = UILineBreakModeWordWrap; titleLabel.numberOfLines = 2; titleLabel.text = aNewsInfo.title; 但是這並沒有在tableView單元中只是空白我應該怎麼做... – user755278 2011-05-31 08:19:37

+0

你改變了標籤的高度,對於動態數據設置numberoflines = 0,如上所述。 – 2011-05-31 09:03:15

+0

是的,我已經改變了所有的高度n正確設置numberofline爲0,但仍然是同樣的問題... – user755278 2011-05-31 18:12:16

0

喜嘗試在你的cellforRow方法中添加標籤

CGSize labelsize; 
    UILabel *commentsTextLabel = [[UILabel alloc] init];; 
    commentsTextLabel.tag =50; 
    [commentsTextLabel setNumberOfLines:0]; 
    [commentsTextLabel setBackgroundColor:[UIColor clearColor]]; 
    NSString *text=[@"dasdasdasdasfasfasfasfasfasfsafasfsafasfasfasfasfsafsafasfasfsaf"]; 
    [commentsTextLabel setFont:[UIFont fontWithName:@"Helvetica"size:14]]; 
    labelsize=[text sizeWithFont:commentsTextLabel.font constrainedToSize:CGSizeMake(268, 2000.0) lineBreakMode:UILineBreakModeWordWrap]; 
    commentsTextLabel.frame=CGRectMake(10, 24, 268, labelsize.height); 
    [cell.contentView addSubview:commentsTextLabel]; 
    [commentsTextLabel release]; 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 

{ 
    CGSize labelsize; 
    UILabel * textDesc1 = [[UILabel alloc] init]; 
    [textDesc1 setNumberOfLines:0]; 
    textDesc1.text=[@"dasdasdasdasfasfasfasfasfasfsafasfsafasfasfasfasfsafsafasfasfsaf"]; 
    [textDesc1 setFont:[UIFont fontWithName:@"Helvetica" size:14.0]]; 
    labelsize=[textDesc1.text sizeWithFont:textDesc1.font constrainedToSize:CGSizeMake(268, 2000.0) lineBreakMode:UILineBreakModeWordWrap]; 
    labelsize.height=labelsize.height+35; 
    [textDesc1 release]; 
    return (CGFloat)labelsize.height; 


}