2012-05-03 4 views
1

私はCustomsセルで構成されるテーブルビューを持っています。 各セルには合計3つのラベルがあります。UITableViewのUILabelの予期しないY座標

大きな問題は、セルの3つのラベルの中間ラベルの形成です。

私は

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"]; 

のように同じCGRectを持つカスタムラベルを作成しています...このラベルは、セル内の各ラベルのために呼び出されますが、それは最初と中間ラベル間の未予想される距離を配っています。

赤は画像内の領域を強調表示を参照してください

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

A 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]; 
関連する問題