用于识别iPhone 6和iPhone 6 plus肖像的尺寸等级 [英] Size class to identify iPhone 6 and iPhone 6 plus portrait

查看:109
本文介绍了用于识别iPhone 6和iPhone 6 plus肖像的尺寸等级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用尺寸等级唯一识别iPhone 6和iPhone 6以及纵向屏幕?

How to uniquely identify iPhone 6 and iPhone 6 plus portrait screens using size classes?

我的应用程序在iPhone 4和iPhone 5中看起来不错但是看起来很像由于屏幕尺寸的原因,iPhone 6和6中的空白区域。虽然使用自动布局但我不能仅为iPhone 6和6加上单独增加字体大小或视图大小。我知道我们可以使用大小类更改字体大小和视图大小。但在我的情况下,不知道该怎么做。

My App looks good in iPhone 4 and iPhone 5 but the same looks with lots of empty spaces in iPhone 6 and 6 plus because of screen sizes. Though am using auto layout i can't increase the font size or view size only for iPhone 6 and 6 plus alone. I knew that we can change the font size and view size using size classes. but in my case don't know what to do.

使用xCode 6.1和我的应用支持从iOS 7到最新的iOS 8.1。我只期待故事板中的解决方案,因为我在故事板中完全完成了我的UI设计。如果故事板具有有限的功能来满足我的需求,请让我知道如何通过应用程序实现相同的代码?

Am using xCode 6.1 and my app supports from iOS 7 to latest iOS 8.1. Am expecting solution only in storyboards as am doing my UI designs fully in storyboard. If storyboard has limited functionality to achieve my needs please let me know how to achieve the same with code through out the app?

推荐答案

根据iPhone类型调整字体大小的另一个选择是使用用户定义的运行时属性。

Another option to adjust the font size according to the iPhone type, is to use 'User Defined Runtime Attributes'.

定义UILabel的扩展名:

Define an extension to UILabel:

extension UILabel {
    var adjustFontToRealIPhoneSize: Bool {
        set {
            if newValue {
                var currentFont = self.font
                var sizeScale: CGFloat = 1
                let model = UIDevice.CurrentDevice().modelName()

                if model == "iPhone 6" {
                    sizeScale = 1.3
                }
                else if model == "iPhone 6 Plus" {
                    sizeScale = 1.5
                }

                self.font = currentFont.fontWithSize(currentFont.pointSize * sizeScale)
            }
        }

        get {
            return false
        }
    }
}

为了确定当前的型号名称,请参考以下答案:https://stackoverflow.com/a/26962452/4165128

In order to determine the current model name, please refer to the following answer: https://stackoverflow.com/a/26962452/4165128

在故事板上,选择您要调整的标签,打开右窗格,选择身份检查器,并将'adjustFontToRealIPhoneSize'属性添加到用户定义的运行时属性列表中(类型为'Boolean'并选中复选框)。

On the storyboard, select the label you wish to adjust, open the right pane, select the identity inspector, and add the 'adjustFontToRealIPhoneSize' property to the list of user defined runtime attributes (with type 'Boolean' and checkbox checked).

对要调整的每个标签执行相同操作(复制和放大)令人惊讶地在这里工作)。

Do the same for each label you wish to adjust (copy & paste surprisingly works here).

这篇关于用于识别iPhone 6和iPhone 6 plus肖像的尺寸等级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆