Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of UIApplication.shared.preferredContentSizeCategory in app extension

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.

like image 614
Zev Eisenberg Avatar asked Dec 30 '16 00:12

Zev Eisenberg


1 Answers

You can use UIScreen.main.traitCollection.preferredContentSizeCategory. The preferredContentSizeCategory property is available on iOS 10 or later.

like image 86
Pablo Avatar answered Nov 15 '22 03:11

Pablo