2 mapmapm MapMapM 于 2013.02.26 09:54 提问

UILabel的sizeThatFits返回高度么?

我在应用中实现下面代码:

themeLabel = [[UILabel alloc] init];
themeLabel.backgroundColor = [UIColor redColor];
themeLabel.text = themeString;
[themeLabel sizeThatFits:CGSizeMake(274, 274)];
themeLabel.numberOfLines = 0;
[topThemeView addSubview:themeLabel];

NSLog(@"Height is %f ", themeLabel.frame.size.height);

[themeLabel setFrame:CGRectMake(leftMargin, mainScrollView.frame.origin.y + topPadding, 274, themeLabel.frame.size.height)];

最终结束的时候Label的高度是0.0,应该怎么解决?

1个回答

redCoral_
redCoral_   2013.02.26 16:30
已采纳
themeLabel = [[UILabel alloc] init];
themeLabel.backgroundColor = [UIColor redColor];
themeLabel.text = themeString;
themeLabel.numberOfLines = 0;

CGRect labelFrame = CGRectMake(leftMargin, mainScrollView.frame.origin.y + topPadding, 0.0, 0.0);
labelFrame.size = [themeLabel sizeThatFits:CGSizeMake(274, 274)];

[themeLabel setFrame:labelFrame];
[topThemeView addSubview:themeLabel];
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!