The iOS interface environment for your app, defined by traits such as horizontal and vertical size class, display scale, and user interface idiom.
SDKs
- iOS 8.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
Framework
- UIKit
Declaration
class UITraitCollection : NSObject
Overview
The iOS trait environment is exposed though the trait
property of the UITrait
protocol. This protocol is adopted by the following classes: UIScreen
, UIWindow
, UIView
, UIPresentation
, and UIView
. To create an adaptive interface, write code to adjust your app’s layout according to changes in these traits. You access specific trait values using the UITrait
horizontal
, vertical
, display
, and user
properties. The values that express idiom and size traits are defined in the UIUser
and UIUser
enumerations; the value for the display scale trait is expressed as a floating point number.
To make your view controllers and views responsive to changes in the iOS interface environment, override the trait
method from the trait environment protocol. To customize view controller animations in response to interface environment changes, override the will
method of the UIContent
protocol.
Figure 1 shows the horizontal (width) and vertical (height) size classes your app can encounter when running on various devices fullscreen.
Size classes

For information about size classes your app encounters in Slide Over and Split View on iPad, read Slide Over and Split View Quick Start in Adopting Multitasking Enhancements on iPad.
You can create standalone trait collections to assist in matching against specific environments. The UITrait
class includes four specialized constructors as well as a constructor that lets you combine an array of trait collections, init(traits
.
One important use of standalone trait collections is to enable conditional use of images based on the current iOS interface environment. You can associate a trait collection with a UIImage
instance by way of a UIImage
instance, as described in the overview section of UIImage
. For information on configuring asset catalogs graphically from within the Xcode IDE, see Asset Catalog Help.
You can employ a standalone trait collection to enable a two-column split view in landscape orientation on iPhone. See the set
method of the UIView
class.
A standalone trait collection is also useful in customizing view appearance, by way of the appearance(for:)
protocol method, as described in UIAppearance
.
3D Touch and Trait Collections
Starting in iOS 9, you can use this class to check whether the device on which your app is running supports 3D Touch. Read the value of the force
property on the trait collection for any object in your app with a trait environment. For information about trait environments, see UITrait
. For the possible values of the force touch capability property, see the UIForce
enumeration.
Because a user can turn off 3D Touch in Settings, check the value of the force
property in your implementation of the trait
method, and adjust your code paths according to the property’s value.