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

烈酒焚心 提交于 2019-12-12 02:05:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!