How do I change the font size according to screen size

梦想的初衷 提交于 2019-12-24 08:12:36

问题


I have added min font size to label but the font is not changing according to the screen size.

I thought setting min font size and using autolayout is to scale the label height is enough.

But its not happening.


回答1:


Use minimum font scale instead of minimum font size. Minimum font size was deprecated in IOS 6. In the image although mine says fixed here you can change that and then set the scale factor.

To vary by size of the screen you can do some of that with interface builder. See image. This is using size classes.

Other ways would be to increase the font size to a large number and let it scale, set it in code by device type, or set a constraint on the label to make it grow and shrink between different sizes and have the scaling set right.




回答2:


TextKit provides the inbuilt support for making UI with Adaptive text font sizing based on auto layouts.

https://developer.apple.com/design/adaptivity/

Check the details on Dynamic text on above article.



来源:https://stackoverflow.com/questions/42674694/how-do-i-change-the-font-size-according-to-screen-size

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