issues with label text layout while changing the f

2019-09-06 08:47发布

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.

2条回答
叛逆
2楼-- · 2019-09-06 09:16

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

查看更多
ゆ 、 Hurt°
3楼-- · 2019-09-06 09:29

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;
}
查看更多
登录 后发表回答