The iOS interface environment, which includes traits such as horizontal and vertical size class, display scale, and user interface idiom, is available to apps through the UITraitEnvironment protocol. The following interface classes adopt this protocol: UIScreen, UIWindow, UIViewController, UIPresentationController, and UIView.


To access the trait environment of an object that adopts this protocol, use the traitCollection property. The protocol also provides an overridable method that the system calls when the interface environment changes. Implement this method as part of creating an adaptive iOS app.

For more about trait collections, see UITraitCollection. For the WWDC 2014 presentation on creating adaptive interfaces in iOS, see Building Adaptive Apps with UIKit.


Accessing a Trait Collection

var traitCollection: UITraitCollection

The trait collection for a view controller (an instance of the UIViewController class or one of its subclasses) or a view (an instance of the UIView class or one of its subclasses).

Responding to a Change in the Interface Environment

func traitCollectionDidChange(UITraitCollection?)

Called when the iOS interface environment changes.