Добавьте это расширение:
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()
}