调整字体大小UITextView不同大小的屏幕上 - Adjust font size in UITextView on screen of different size

- 此内容更新于:2015-12-13
主题:

我有一个UITextView一些文本。我想要大屏幕上有较大的字体大小,但是格式是相同的。我怎么能这样做呢?

原文:

I have a UITextView with some texts. I want the big screen has bigger font size but the format is same. How can I do this?

网友:你的意思是当你说“大屏幕”?iPhone更大的屏幕像iPhone6iPhone5或6+比较?

(原文:What do you mean when you say "big screen" ? bigger iPhone screen like iPhone 6 or 6 plus comparing to the iPhone 5 ?)

解决方案:
我知道这是一个更先进的比-代码解决方案你已经在这里找到,但我将鼓励你花一些时间,了解自适应布局:这是UI开发的未来不同的屏幕在iOS。例如,您可以针对不同的屏幕尺寸和取向使用大小类。在这里你可以得到概述:宽度和高度特征。这里有一些指针如果你需要开始从零:苹果-自适应用户界面苹果自适应性和布局射线Wenderlich-自适应布局开始教程图坦卡蒙+介绍自适应设计自适应布局为iPhone6
原文:

I know it's a bit more advanced than the code-only solutions you've already found here, but I would encourage you to take some time and read about Adaptive Layouts: it's the future of UI development for different screens on iOS.

For instance, you can target different screen sizes and orientations using size classes. You can get an overview here: width & height traits.

Here are a few pointers if you need to begin from zero:

解决方案:
你可以使用和检测设备的屏幕大小根据屏幕大小你是你设置一个不同的字体大小。见下面的例子:在这里你可以在这里查看屏幕尺寸
原文:

You can detect the screen size of the device using UIScreen.mainScreen().bounds.height and depending on the screen size you are you set a different font size.

See example below:

let screenHeight = UIScreen.mainScreen().bounds.height

switch screenHeight {
case 480: // 3.5 inch
    UIFont(name: "Helvetica", size: 16)
case 568: // 4 inch
    UIFont(name: "Helvetica", size: 17)
default: // rest of screen sizes
    UIFont(name: "Helvetica", size: 20)
}

Here you can check out the screen sizes here

解决方案:
你可以检查,iPhone用户使用模式。要做到这一点,使用的代码在他的回答这个问题。所以你可以得到iPhone模型是这样的:你可以设置字体大小基于iPhone模型。
原文:

You can check, which iPhone model the user is using. To do that, use the code from HAS in his answer to this question.

So you can get the iPhone model like this:

let modelName = UIDevice.currentDevice().modelName

Then you can set the font-size based on the iPhone model.