Ios5 UITableView中UILabel的意外Y坐标
我有一个由海关单元组成的tableview。 每个单元格总共有三个标签 主要问题是单元格三个标签中间标签的形成 我正在创建一个与CGRect相同的自定义标签Ios5 UITableView中UILabel的意外Y坐标,ios5,xcode4,uitableview,uilabel,custom-cell,Ios5,Xcode4,Uitableview,Uilabel,Custom Cell,我有一个由海关单元组成的tableview。 每个单元格总共有三个标签 主要问题是单元格三个标签中间标签的形成 我正在创建一个与CGRect相同的自定义标签 UILabel *msglabeltemp = [[[UILabel alloc] initWithFrame: CGRectMake(80,20.0,230.0,80.0)] autorelease]; [cell.contentView addSubview:msglabeltemp]; msglabeltemp.backgroun
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"];
。。。将为单元格中的每个标签调用此标签,但它给出了第一个标签和中间标签之间的非预期距离
请参见图像中的红色突出显示区域
A
UILabel
的内容不是顶部对齐(而是居中),这就是为什么您会看到这一点
请参阅以获取有关如何更改此设置的灵感。A
UILabel
的内容不是顶部对齐的(而是居中),这就是您看到此设置的原因
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];
有关如何改变这一点的灵感,请参阅。这也很有用
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];
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;
这也是有用的
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;