答案 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")
}
}
}
现在您可以在任何UIViewController
,UIView
等中使用它了:
override func viewDidLoad() {
super.viewDidLoad()
printCurrentContentSizeCategory()
}