使用自动布局更改应用程序的字体时,标签文本布局的问题 [英] issues with label text layout while changing the font for app using auto layout

查看:297
本文介绍了使用自动布局更改应用程序的字体时,标签文本布局的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序的自动布局工作。我有一个功能,通过滑块移动增加整个应用程序的字体大小。问题是当我增加字体大小的标签文本变成椭圆。

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 ?

任何帮助将赞赏。

推荐答案

尝试:

从上,左和右侧,然后使标签高度大于或等于但不从下侧。

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;
}

这篇关于使用自动布局更改应用程序的字体时,标签文本布局的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆