简体   繁体   English

通过设备尺寸调整iOS自动布局字体(iPhone 6 plus,iPhone 6,iPhone 5)

[英]iOS Autolayout font adjustment with device size (iPhone 6 plus, iPhone 6, iPhone 5)

I am using autolayout and setting font in UILabel, or UITextField in wAny hAny size class. 我正在使用自动布局并在UILabel或wAny hAny size类的UITextField中设置字体。

Font looks good in iPhone 6 plus but on iPhone 5 its size does not change. 字体在iPhone 6 plus中看起来不错,但在iPhone 5上它的大小没有变化。

If we take example of UILabel, I set horizontal center and verticle center without giving width and Height. 如果我们以UILabel为例,我设置了水平中心和垂直中心而没有给出width和Height。

How to make its font responsive with particular device size of iPhone. 如何使其字体响应iPhone的特定设备尺寸。

Cheers 干杯

There is 2 solutions: 有两种解决方案:

  1. Instead of setting the a vertical center constraint, set a leading and a tailing constraints. 代替设置垂直中心约束,而设置前导约束和尾随约束。 Set your text alignment to center. 将文本对齐方式设置为居中。
    Then set the label's autoshrink property to "Minimum font scale/size" and you are good to go. 然后将标签的自动收缩属性设置为“最小字体比例/大小”,一切就好了。
  2. Use size classes on your font (by clicking the tiny "+" near your font name). 在字体上使用尺寸类别(通过单击字体名称旁边的小“ +”号)。
    This won't work with custom fonts because of an Xcode 6/7 bug (Apple is aware of this). 由于Xcode 6/7的错误(Apple意识到这一点),这不适用于自定义字体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM