为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.