Julian A.
Julian A.

Reputation: 11450

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

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?

Upvotes: 6

Views: 1825

Answers (1)

Julian A.
Julian A.

Reputation: 11450

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.

Upvotes: 11

Related Questions