9

My open source library needs to be able to call UIApplication.shared.preferredContentSizeCategory. But UIApplication.shared is unavailable in extensions. The build error suggests that I find a view controller-based way to solve my problem, but I'm writing a library, so I don't have access to any view controllers. Is there a way to get the root view controller of an extension, or a way to get the outermost UITraitEnvironment?

I support iOS 9+, but this feature could be 10+ if that makes it possible.

4

1 回答 1

8

您可以使用UIScreen.main.traitCollection.preferredContentSizeCategory. 该preferredContentSizeCategory属性适用于 iOS 10 或更高版本。

于 2017-11-24T15:16:50.180 回答