为iPhone 5和6设置不同的字体大小 [英] Set different font size for iPhone 5 and 6

查看:214
本文介绍了为iPhone 5和6设置不同的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索过但尚未找到答案。

I have searched for but not found an answer to this yet.

我想为iPhone 5和6设置不同的标签字体大小。我知道我可以为Compact Width设置特定的布局,但5和6都属于那个小组。有没有办法做到这一点?

I would like to set different font sizes of labels for iPhone 5 and 6. I know that I can set specific layout for Compact Width, but both 5 and 6 belong to that group. Is there a way to do this?

推荐答案

我的助手扩展名:

extension UIFont {
    static var sizeMultiplier: CGFloat {
        return UIDevice.current.isPhone5 ? 0.85 : 1
    }

    static func regular(_ size: CGFloat) -> UIFont {
        return UIFont(name: "SFUIText-Regular", size: size * sizeMultiplier)!
    }

    static func bold(_ size: CGFloat) -> UIFont {
        return UIFont(name: "SFUIText-Bold", size: size * sizeMultiplier)!
    }
}

用法:

titleLabel.font = .bold(16)

我也在寻找一种解决方案,在运行时属性中附加特定于iPhone5的大小。

I'm also looking for a solution to attach the iPhone5-specific size in the runtime attributes.

这篇关于为iPhone 5和6设置不同的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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