问题描述
- 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,应该怎么解决?
解决方案
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];
时间: 2024-11-02 06:18:54