问题
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.
回答1:
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;
}
回答2:
You should be able to set word wrap and specify a large number of lines, say 30
. this should do the trick.
来源:https://stackoverflow.com/questions/25638837/issues-with-label-text-layout-while-changing-the-font-for-app-using-auto-layout