xcode iOS Storyboard - 有什么方法可以根据屏幕大小更改字体大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43707915/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 09:56:41  来源:igfitidea点击:

iOS Storyboard - any way to change font size based on screen size?

iosiphoneswiftxcodestoryboard

提问by Michael

I want to be able to scale the font size on a storyboard per screen size without writing code to do this, is this possible.

我希望能够在不编写代码的情况下按屏幕尺寸缩放故事板上的字体大小,这可能吗。

I already tried to set up constraints to adjust the label and set the font scaling factor but what happens then it depending on how long the text is I end up getting a screen that has different font sizes rather than all of the font for that screen being the same size?

我已经尝试设置约束来调整标签并设置字体缩放因子但是会发生什么取决于文本的长度我最终得到一个具有不同字体大小的屏幕而不是该屏幕的所有字体一样大吗?

回答by Hyman

Xcode provides auto shrinks facility, Which adjust based on screen size Goto Attribute inspector-> Autoshrinks -> Minimum font scale set it to 0.5or your desired value.

Xcode 提供自动缩小功能,根据屏幕大小进行调整 Goto Attribute inspector-> Autoshrinks -> Minimum font scale 将其设置为 0.5或您想要的值。

enter image description here

enter image description here

Programmatically

以编程方式

label.adjustsFontSizeToFitWidth = true
label.minimumScaleFactor = 0.5

回答by LinusGeffarth

You can add variations inside the property inspector based on the different devices:

您可以根据不同的设备在属性检查器中添加变体:

Property Inspector: Label

Property Inspector: Label

Note, however, that this will not distinguish between all devices...

但是请注意,这不会区分所有设备......