Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access and manipulate size classes in code for iOS 8

Tags:

ios

ios8

size

There's a decent amount of information online about using size classes in XCode for iOS 8, but little or nothing about reading, interpreting, or manipulating size classes in code. Is doing so in code even an option?

like image 274
Julian A. Avatar asked Oct 25 '14 19:10

Julian A.


1 Answers

Of course, once again I find what I've been looking for after(!) I post on SO :)

In iOS 8, there is in fact a class UITraitCollection that has information about size class.

To get access to it when it changes, any UIViewController can override methods of either of 2 protocols that UIViewController implements:

UIContentContainer - viewWillTransitionToTraitCollection:withTransitionCoordinator:

UITraitEnvironment - traitCollectionDidChange:

Even easier, self.traitCollection can be accessed within any UIViewController.

like image 137
Julian A. Avatar answered Oct 10 '22 22:10

Julian A.