2012-05-03 23 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];