UILabel调整高度不起作用
问题描述:
我有以下代码来调整标签的高度,但它不起作用。 它显示的文字..... 我做错了什么?UILabel调整高度不起作用
float storeAddress1YOffset=10;
float storeAddress1XWidth=scrollView.frame.size.width;
float storeAddressLabel1YHeight=15;
UILabel *storeAddressLabel=[[UILabel alloc]initWithFrame:CGRectMake(Xoffset,storeSectionHeight+ storeAddress1YOffset,storeAddress1XWidth, storeAddressLabel1YHeight) ];
storeAddressLabel.font=[UIFont fontWithName:@"GillSans" size:15.0f];
currentHeight=currentHeight + storeAddress1YOffset + storeAddressLabel1YHeight;
[storeAddressLabel setText:fullAddress];
CGRect labelFrame = storeAddressLabel.frame;
labelFrame.size = [fullAddress sizeWithFont:storeAddressLabel.font
constrainedToSize:CGSizeMake(storeAddressLabel.frame.size.width, CGFLOAT_MAX)
lineBreakMode:storeAddressLabel.lineBreakMode];
storeAddressLabel.frame = labelFrame;
答
您的代码似乎适用于我。有几个变量,你没有实例:
float Xoffset = ?;
float storeSectionHeight = ?;
float currentHeight = ?;
NSString *fullAddress = @"?";
除了你不显示有关scrollView
或添加storeAddressLabel
来(我假设)scrollView
作为一个子视图的任何细节。
当我使用普通的UIView
填充这些缺失的部分时,标签似乎正确调整为测试字符串fullAddress
。请包含一些更多的代码,包括这些缺失的部分。
我通过在初始化帧标签之前确定帧大小来了解它的工作原理。 – user1688346