问题描述
我在纵向模式下工作.我正在寻找一种方法来更改标签中文本的字体大小,使其仅适用于 iPhone 4s.我知道常规高度/紧凑宽度适用于 iPhone 4s、5 和 6.但是对于我的应用程序,我必须将字体大小设置得如此之小,以使其与 4s 兼容.在 5 上看起来还不错,但是在 6 上观看时非常难看(因为它看起来非常小).在这种情况下,你们会怎么做?
I'm working in Portrait mode. I'm looking for a way to change the font size of text in a label so it only applies to the iPhone 4s. I understand that regular height/compact width applies to the iPhone 4s, 5, and 6. But with my app the way it is, I have to make my font size so small just to make it 4s compatible. On the 5 it looks alright, but it makes viewing it on the 6 very very ugly (being of how miniscule it looks). What would you guys do in this situation?
有没有办法以编程方式做到这一点?如果这不可能,苹果怎么会错过呢?将 4s 放在它自己的子类别中,就其高度而言不是更有意义吗?
Is there any way to do this programmatically even? If this isn't possible, how could Apple miss this? Doesn't it make more sense to put the 4s in it's own subcategory with regards to it's height?
我正在用 Swift 编程.
I am programming in Swift.
推荐答案
检测设备型号:
if UIDevice.currentDevice().model == "iPhone4,1" {
// do whatever you want here for iPhone 4S
} else {
// other devices
}
nativeBounds
物理屏幕的边界矩形,以像素为单位.(只读)
申报 SWIFT
var nativeBounds: CGRect { get }
此矩形基于纵向向上的设备.这个值不会随着设备旋转而改变.
This rectangle is based on the device in a portrait-up orientation. This value does not change as the device rotates.
进口声明
import UIKit
检测设备的高度:
if UIScreen.mainScreen().nativeBounds.height == 960.0 {
}
检测设备的宽度:
if UIScreen.mainScreen().nativeBounds.width == 640.0 {
}
这篇关于仅针对 iPhone 4s 更改标签中的字体大小,这可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!