gpt4 book ai didi

iphone - UILabel 的 sizeThatFits 是否返回它的高度?

转载 作者:可可西里 更新时间:2023-11-01 03:43:45 24 4
gpt4 key购买 nike

我正在尝试在我的应用中实现以下内容:

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

关于iphone - UILabel 的 sizeThatFits 是否返回它的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15069115/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com