如何知道Swift的iOS字体大小(或百分比)?

时间:2019-03-25 18:23:48

标签: ios swift

我想知道Swift中iOS的字体大小(或百分比)吗?我知道通过使用动态类型,标签会自行调整,但是我想知道它是百分之几,中间是最小还是最大?

图像样本: Image Sample

1 个答案:

答案 0 :(得分:0)

添加此扩展名:

extension UITraitEnvironment {
    func printCurrentContentSizeCategory() {
        switch traitCollection.preferredContentSizeCategory {
        case .extraSmall:
            print("extra small")
        case .small:
            print("small")
        case .medium:
            print("medium")
        case .large:
            print("large")
        case .extraLarge:
            print("extra large")
        case .extraExtraLarge:
            print("extra extra large")
        case .extraExtraExtraLarge:
            print("extra extra extra large")
        case .accessibilityMedium:
            print("accessibility medium")
        case .accessibilityLarge:
            print("accessibility large")
        case .accessibilityExtraLarge:
            print("accessibility extra large")
        case .accessibilityExtraExtraLarge:
            print("accessibility extra extra large")
        case .accessibilityExtraExtraExtraLarge:
            print("accessibility extra extra extra large")
        default:
            print("Unspecified")
        }
    }
}

现在您可以在任何UIViewControllerUIView等中使用它了:

override func viewDidLoad() {
    super.viewDidLoad()
    printCurrentContentSizeCategory()
}