Reputation: 1970
I have the following code to resize height of the label but it isn't working. It is showing the text with ..... What did i do wrong?
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;
Upvotes: 0
Views: 241
Reputation: 5579
Your code seems to work for me. There are a few variables you didn't instantiate:
float Xoffset = ?;
float storeSectionHeight = ?;
float currentHeight = ?;
NSString *fullAddress = @"?";
As well as you don't show any details about scrollView
or adding storeAddressLabel
to (I'm assuming) scrollView
as a subview.
When I filled in these missing pieces, using a plain UIView
, the label appeared resized correctly to a test string fullAddress
. Please include some more of your code, including these missing pieces.
Upvotes: 1