Vikas Ojha
Vikas Ojha

Reputation: 444

issues with label text layout while changing the font for app using auto layout

I am working on auto layout in my app.I have a functionality to increase the font size of entire app through slider movement.The issue is when i increase the font size the text of the label turns into ellipses.

I have given the constraints to my label a fixed width and increasing variable height but this doesn't solve any problem.

Do i need to give line break mode (word-wrap) and specify the number of lines for every text or there any other solution to this ?

Any help will be appreciated.

Upvotes: 0

Views: 162

Answers (2)

Pritesh
Pritesh

Reputation: 980

Try This:

First bound constrain to label from upper, left and right side and then make the label height greater than or equal but don't bound from down side.

then use the following code to increase label height dynamically:

-(float)expectedHeightWithFontSize:(CGFloat)fontSize
{
CGRect lblTextSize = [self.yourLabel.text boundingRectWithSize:CGSizeMake(self.yourLabel.frame.size.width, MAXFLOAT)
                   options:NSStringDrawingUsesLineFragmentOrigin
                attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]}
                   context:nil];
return lblTextSize.size.height;
}

Upvotes: 4

sam34543
sam34543

Reputation: 21

You should be able to set word wrap and specify a large number of lines, say 30. this should do the trick.

Upvotes: 0

Related Questions