Xcode 6 中不同设备的不同字体大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28924836/
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 06:47:16  来源:igfitidea点击:

Different font size for different devices in Xcode 6

iosxcodeswiftxcode6

提问by hidayat

I want to use the same text on different devices. I am using the universal storyboard but I can't find any constraints for the font size. I know that you can use different text fields on different devices with the new layout but then I need to add some logic in the code. I want to use same text field.

我想在不同的设备上使用相同的文本。我正在使用通用故事板,但我找不到任何字体大小的限制。我知道您可以在具有新布局的不同设备上使用不同的文本字段,但随后我需要在代码中添加一些逻辑。我想使用相同的文本字段。

回答by Magnas

Select your text field in your storyboard. In the attributes inspector you will see a small '+' to the left of the font selector. This will allow you to choose size-class specific stuff for your text.

在故事板中选择文本字段。在属性检查器中,您将在字体选择器的左侧看到一个小“+”。这将允许您为文本选择特定大小的内容。

Size classes were added to iOS 8 when Apple introduced Universal Storyboards which let you design for both iPad and iPhone with the same Storyboard file. At the bottom of the Storyboard design window you'll see the (default) 'w Any h Any' button. This gives you access to combinations of the compact and regular size classes. These available combinations let you implement design, say for only the iPhone in landscape, or maybe the iPad in both orientations. You have full control.

当 Apple 推出 Universal Storyboards 时,iOS 8 中添加了大小类,它允许您使用相同的 Storyboard 文件为 iPad 和 iPhone 进行设计。在 Storyboard 设计窗口的底部,您将看到(默认)“w Any h Any”按钮。这使您可以访问紧凑型和常规尺寸类的组合。这些可用的组合让您可以实现设计,例如仅适用于横向的 iPhone,或者适用于两个方向的 iPad。你有完全的控制权。

For your font related question, you access the size-class control through the '+' sign I mentioned above.

对于与字体相关的问题,您可以通过我上面提到的“+”号访问 size-class 控件。

This is a good explanation and tutorial: Wenderlich size classes

这是一个很好的解释和教程: Wenderlich size classes

and in Apple's own words: Apple size classes

用 Apple 自己的话来说: Apple size classes

EDIT: - If you really want to have different font sizes for different screen sizes, then thisanswer should help you.

编辑: - 如果你真的想为不同的屏幕尺寸使用不同的字体大小,那么这个答案应该对你有所帮助。