2012-05-03 48 views
1

協調的UILabel我有它由海關細胞的tableview。 每個單元的總共具有三個標籤。意外的Y的UITableView

的主要問題是電池的三個標籤的中間標籤的形成。

我創建具有相同的CGRect自定義標籤一樣

UILabel *msglabeltemp = [[[UILabel alloc]  initWithFrame:  CGRectMake(80,20.0,230.0,80.0)] autorelease]; 
[cell.contentView addSubview:msglabeltemp]; 
msglabeltemp.backgroundColor = [UIColor clearColor]; 
msglabeltemp.textColor = [UIColor grayColor]; 
msglabeltemp.numberOfLines=6; 
[msglabeltemp setFont:[UIFont fontWithName:@"Helvetica Neue" size:12.0f]]; 
msglabeltemp.tag=1; 
msglabeltemp.font=[UIFont systemFontOfSize:12.0f]; 
msglabeltemp.textAlignment=UITextAlignmentLeft ; 
//Adding Label To Cell 
UILabel *msglabel = (UILabel *)[cell.contentView viewWithTag:1]; 

msglabel.text = [data1 objectForKey:@"msg"]; 

...這個標籤將被要求在小區內的每個標籤,但它是贈送的第一和中間標籤之間未預期的距離。

看到紅色的圖像

enter image description here

回答

1

這也有用

CGSize maximumSize = CGSizeMake(300, 9999); 
    NSString *dateString = @"The date today is January 1st, 1999"; 
    UIFont *dateFont = [UIFont fontWithName:@"Helvetica" size:14]; 
    CGSize dateStringSize = [dateString sizeWithFont:dateFont 
      constrainedToSize:maximumSize 
      lineBreakMode:self.dateLabel.lineBreakMode]; 

    CGRect dateFrame = CGRectMake(10, 10, 300, dateStringSize.height); 

    self.dateLabel.frame = dateFrame; 
0

一個UILabel的內容不是頂部對齊所強調的區域(而不是它的中間爲中心),這就是爲什麼你看到這一點。

請參閱Vertically align text to top within a UILabel以獲取有關如何更改此設置的靈感。

0
CGRect lblFrame = CGRectMake(20, 20, 280, 150); 
    UILabel *lbl = [[UILabel alloc] initWithFrame:lblFrame]; 
    [lbl setBackgroundColor:[UIColor orangeColor]]; 

    NSString *labelText = @"I am the very model of a modern Major-General, I've information vegetable, animal, and mineral"; 
    [lbl setText:labelText]; 

    // Tell the label to use an unlimited number of lines 
    [lbl setNumberOfLines:0]; 
    [lbl sizeToFit];