<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UITraitCollection",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UITraitCollection"
  },
  "title" : "UITraitCollection"
}
-->

# UITraitCollection

A collection of data that represents the environment for an individual element in your app’s user interface.

```
class UITraitCollection
```

## Overview

The [`traitCollection`](/documentation/UIKit/UITraitEnvironment/traitCollection) property of the [`UITraitEnvironment`](/documentation/UIKit/UITraitEnvironment) protocol contains traits that describe the state of various elements of the iOS user interface, such as size class, display scale, and layout direction. Together, these traits compose the UIKit trait environment.

The following classes adopt [`UITraitEnvironment`](/documentation/UIKit/UITraitEnvironment): [`UIScreen`](/documentation/UIKit/UIScreen), [`UIWindow`](/documentation/UIKit/UIWindow), [`UIWindowScene`](/documentation/UIKit/UIWindowScene), [`UIViewController`](/documentation/UIKit/UIViewController), [`UIPresentationController`](/documentation/UIKit/UIPresentationController), and [`UIView`](/documentation/UIKit/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 [`UITraitCollection`](/documentation/UIKit/UITraitCollection) [`horizontalSizeClass`](/documentation/UIKit/UITraitCollection/horizontalSizeClass), [`verticalSizeClass`](/documentation/UIKit/UITraitCollection/verticalSizeClass), [`displayScale`](/documentation/UIKit/UITraitCollection/displayScale), [`userInterfaceIdiom`](/documentation/UIKit/UITraitCollection/userInterfaceIdiom), and other properties.

To make your view controllers and views responsive to changes in the iOS interface environment, use automatic trait tracking in supported [`UIViewController`](/documentation/UIKit/UIViewController) and [`UIView`](/documentation/UIKit/UIView) methods, or register to track specific trait changes with [`UITraitChangeObservable`](/documentation/UIKit/UITraitChangeObservable-67e94) methods. For more information, see [Adapting your app when traits change](/documentation/UIKit/adapting-your-app-when-traits-change).

To customize view controller animations in response to interface environment changes, override the [`willTransition(to:with:)`](/documentation/UIKit/UIContentContainer/willTransition(to:with:)) method of the [`UIContentContainer`](/documentation/UIKit/UIContentContainer) protocol.

For more information about the horizontal (width) and vertical (height) size classes your app can encounter when running full-screen on various devices, see Human Interface Guidelines > <doc://com.apple.documentation/design/Human-Interface-Guidelines/layout>.

You can create standalone trait collections to assist in matching against specific environments. The [`UITraitCollection`](/documentation/UIKit/UITraitCollection) class includes four specialized constructors, as well as a constructor that enables you to combine an array of trait collections, [`init(traitsFrom:)`](/documentation/UIKit/UITraitCollection/init(traitsFrom:)).

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`](/documentation/UIKit/UIImage) instance by way of a [`UIImageAsset`](/documentation/UIKit/UIImageAsset) instance, as described in the overview section of [`UIImageAsset`](/documentation/UIKit/UIImageAsset). For information on configuring asset catalogs graphically from within the Xcode IDE, see <doc://com.apple.documentation/documentation/Xcode/managing-assets-with-asset-catalogs>.

You can employ a standalone trait collection to enable a two-column split view in landscape orientation on iPhone. See the [`setOverrideTraitCollection(_:forChild:)`](/documentation/UIKit/UIViewController/setOverrideTraitCollection(_:forChild:)) method of the [`UIViewController`](/documentation/UIKit/UIViewController) class.

You can also use a standalone trait collection to customize view appearance with the [`appearance(for:)`](/documentation/UIKit/UIAppearance/appearance(for:)) protocol method, as described in [`UIAppearance`](/documentation/UIKit/UIAppearance).

For information on creating custom traits, see [Providing data to the view hierarchy with custom traits](/documentation/UIKit/providing-data-to-the-view-hierarchy-with-custom-traits).

## Topics

### Getting the current traits

[`current`](/documentation/UIKit/UITraitCollection/current)

The trait collection for the current execution context.

### Getting related traits

[`systemTraitsAffectingColorAppearance`](/documentation/UIKit/UITraitCollection/systemTraitsAffectingColorAppearance-18zhm)

[`systemTraitsAffectingColorAppearance`](/documentation/UIKit/UITraitCollection/systemTraitsAffectingColorAppearance-64z7q)

[`systemTraitsAffectingImageLookup`](/documentation/UIKit/UITraitCollection/systemTraitsAffectingImageLookup-640w8)

[`systemTraitsAffectingImageLookup`](/documentation/UIKit/UITraitCollection/systemTraitsAffectingImageLookup-4jv5)

### Modifying traits

[`init(mutations:)`](/documentation/UIKit/UITraitCollection/init(mutations:))

[`modifyingTraits(_:)`](/documentation/UIKit/UITraitCollection/modifyingTraits(_:))

[`UITraitCollection.TraitMutations`](/documentation/UIKit/UITraitCollection/TraitMutations)

[`traitCollectionWithTraits:`](/documentation/UIKit/UITraitCollection/traitCollectionWithTraits:)

[`traitCollectionByModifyingTraits:`](/documentation/UIKit/UITraitCollection/traitCollectionByModifyingTraits:)

[`UITraitMutations`](/documentation/UIKit/UITraitMutations)

### Getting trait changes

[`changedTraits(from:)`](/documentation/UIKit/UITraitCollection/changedTraits(from:))

### Comparing trait collections

[`hasDifferentColorAppearance(comparedTo:)`](/documentation/UIKit/UITraitCollection/hasDifferentColorAppearance(comparedTo:))

Queries whether changing between the specified and current trait collections would affect color values.

[`containsTraits(in:)`](/documentation/UIKit/UITraitCollection/containsTraits(in:))

Queries whether a trait collection contains all of another trait collection’s values.

### Performing actions with the current traits

[`performAsCurrent(_:)`](/documentation/UIKit/UITraitCollection/performAsCurrent(_:))

Executes custom code using the traits of the receiving trait collection.

### Retrieving size class traits

[`horizontalSizeClass`](/documentation/UIKit/UITraitCollection/horizontalSizeClass)

The horizontal size class of the trait collection.

[`verticalSizeClass`](/documentation/UIKit/UITraitCollection/verticalSizeClass)

The vertical size class of the trait collection.

[`UIUserInterfaceSizeClass`](/documentation/UIKit/UIUserInterfaceSizeClass)

Constants that indicate the size class of a view.

### Retrieving display-related traits

[`displayScale`](/documentation/UIKit/UITraitCollection/displayScale)

The display scale of the trait collection.

[`displayGamut`](/documentation/UIKit/UITraitCollection/displayGamut)

The gamut of the current display.

[`UIDisplayGamut`](/documentation/UIKit/UIDisplayGamut)

Constants that indicate the gamut of the current display.

### Retrieving interface-related traits

[`userInterfaceStyle`](/documentation/UIKit/UITraitCollection/userInterfaceStyle)

The style associated with the user interface.

[`UIUserInterfaceStyle`](/documentation/UIKit/UIUserInterfaceStyle)

Constants that indicate the interface style for the app.

[`userInterfaceIdiom`](/documentation/UIKit/UITraitCollection/userInterfaceIdiom)

The user interface idiom of the trait collection.

[`UIUserInterfaceIdiom`](/documentation/UIKit/UIUserInterfaceIdiom)

Constants that indicate the interface type for the device or an object that has a trait environment, such as a view and view controller.

[`userInterfaceLevel`](/documentation/UIKit/UITraitCollection/userInterfaceLevel)

The elevation level of the interface.

[`UIUserInterfaceLevel`](/documentation/UIKit/UIUserInterfaceLevel)

Constants that indicate the visual level for content in the window.

[`layoutDirection`](/documentation/UIKit/UITraitCollection/layoutDirection)

The layout direction associated with the current environment.

[`UITraitEnvironmentLayoutDirection`](/documentation/UIKit/UITraitEnvironmentLayoutDirection)

Constants that indicate the layout direction associated with the current environment.

[`resolvesNaturalAlignmentWithBaseWritingDirection`](/documentation/UIKit/UITraitCollection/resolvesNaturalAlignmentWithBaseWritingDirection-97osy)

Specifies the behavior for resolving `NSTextAlignment.natural` to the visual alignment.

[`resolvesNaturalAlignmentWithBaseWritingDirection`](/documentation/UIKit/UITraitCollection/resolvesNaturalAlignmentWithBaseWritingDirection-58wlh)

[`accessibilityContrast`](/documentation/UIKit/UITraitCollection/accessibilityContrast)

The accessibility contrast associated with the current environment.

[`UIAccessibilityContrast`](/documentation/UIKit/UIAccessibilityContrast)

Constants that indicate the accessibility contrast setting.

[`legibilityWeight`](/documentation/UIKit/UITraitCollection/legibilityWeight)

The font weight to apply to text.

[`UILegibilityWeight`](/documentation/UIKit/UILegibilityWeight)

Constants that indicate the weight to apply to text in your interface.

[`activeAppearance`](/documentation/UIKit/UITraitCollection/activeAppearance)

A property that indicates whether the user interface has an active appearance.

[`UIUserInterfaceActiveAppearance`](/documentation/UIKit/UIUserInterfaceActiveAppearance)

Constants that indicate whether the user interface has an active appearance.

[`toolbarItemPresentationSize`](/documentation/UIKit/UITraitCollection/toolbarItemPresentationSize)

The presentation size of a toolbar item in an AppKit toolbar.

[`UINSToolbarItemPresentationSize`](/documentation/UIKit/UINSToolbarItemPresentationSize)

Constants that specify the presentation size of a toolbar item in an AppKit toolbar.

[`hdrHeadroomUsageLimit`](/documentation/UIKit/UITraitCollection/hdrHeadroomUsageLimit)

If HDR headroom should be used for the current UI configuration. Headroom usage is disabled in certain UI configurations, such as when all an application’s windows are in the background.

[`UIHDRHeadroomUsageLimit`](/documentation/UIKit/UIHDRHeadroomUsageLimit)

### Retrieving the force touch capability traits

[`forceTouchCapability`](/documentation/UIKit/UITraitCollection/forceTouchCapability)

The force touch capability value of the trait collection.

[`UIForceTouchCapability`](/documentation/UIKit/UIForceTouchCapability)

Keys that indicate the availability of 3D Touch on a device.

### Retrieving content size category information

[`preferredContentSizeCategory`](/documentation/UIKit/UITraitCollection/preferredContentSizeCategory)

The font sizing option preferred by the user.

[`UIContentSizeCategory`](/documentation/UIKit/UIContentSizeCategory)

Constants that indicate the preferred size of your content.

[`UIContentSizeCategoryCompareToCategory`](/documentation/UIKit/UIContentSizeCategoryCompareToCategory)

Compares two content size category values to determine whether they are equal or whether one is larger than the other.

[`UIContentSizeCategoryIsAccessibilityCategory`](/documentation/UIKit/UIContentSizeCategoryIsAccessibilityCategory)

Returns a Boolean value that indicates whether the content size category belongs to the group of accessibility-related sizes.

### Retrieving layout environment traits

[`listEnvironment`](/documentation/UIKit/UITraitCollection/listEnvironment)

The list environment represents whether a given trait collection is from a view in a UITableView or a UICollectionView list section.

[`UIListEnvironment`](/documentation/UIKit/UIListEnvironment)

Constants that indicate the style of the containing list in a collection view or table view.

[`splitViewControllerLayoutEnvironment`](/documentation/UIKit/UITraitCollection/splitViewControllerLayoutEnvironment)

The split view controller layout environment represents whether an ancestor split view controller is expanded or collapsed.

[`UISplitViewController.LayoutEnvironment`](/documentation/UIKit/UISplitViewController/LayoutEnvironment)

Constants that indicate the current layout of the containing split view controller.

[`tabAccessoryEnvironment`](/documentation/UIKit/UITraitCollection/tabAccessoryEnvironment)

The tab accessory environment represents whether a given trait collection is from a view in a `UITabAccessory` content view.

[`UITabAccessory.Environment`](/documentation/UIKit/UITabAccessory/Environment)

### Retrieving scene capture state

[`sceneCaptureState`](/documentation/UIKit/UITraitCollection/sceneCaptureState)

Scene capture state represents whether a scene is currently being mirrored or recorded.

[`UISceneCaptureState`](/documentation/UIKit/UISceneCaptureState)

### Retrieving dynamic range traits

[`imageDynamicRange`](/documentation/UIKit/UITraitCollection/imageDynamicRange)

The imageDynamicRange determines how HDR images will render in the given trait environment. SDR images are unaffected.

### Retrieving typesetting language traits

[`typesettingLanguage`](/documentation/UIKit/UITraitCollection/typesettingLanguage-6i635)

[`typesettingLanguage`](/documentation/UIKit/UITraitCollection/typesettingLanguage-1n1fs)

### Getting an image configuration object

[`imageConfiguration`](/documentation/UIKit/UITraitCollection/imageConfiguration)

An image configuration object compatible with this trait collection.

### Creating a trait collection

[`init()`](/documentation/UIKit/UITraitCollection/init())

Creates a trait collection whose traits are set to their default (unspecified) values.

[`init(userInterfaceIdiom:)`](/documentation/UIKit/UITraitCollection/init(userInterfaceIdiom:))

Creates a trait collection that contains only a specified interface idiom.

[`init(horizontalSizeClass:)`](/documentation/UIKit/UITraitCollection/init(horizontalSizeClass:))

Creates a trait collection that contains only a specified horizontal size class.

[`init(verticalSizeClass:)`](/documentation/UIKit/UITraitCollection/init(verticalSizeClass:))

Creates a trait collection that contains only a specified vertical size class.

[`init(userInterfaceStyle:)`](/documentation/UIKit/UITraitCollection/init(userInterfaceStyle:))

Creates a trait collection that contains only the specified user interface style trait.

[`init(accessibilityContrast:)`](/documentation/UIKit/UITraitCollection/init(accessibilityContrast:))

Creates a trait collection that contains only the specified accessibility contrast trait.

[`init(userInterfaceLevel:)`](/documentation/UIKit/UITraitCollection/init(userInterfaceLevel:))

Creates a trait collection that contains only the specified user interface level trait.

[`init(legibilityWeight:)`](/documentation/UIKit/UITraitCollection/init(legibilityWeight:))

Creates a trait collection that contains only the specified legibility weight trait.

[`init(forceTouchCapability:)`](/documentation/UIKit/UITraitCollection/init(forceTouchCapability:))

Creates a trait collection that contains only a specified force touch capability trait.

[`init(displayScale:)`](/documentation/UIKit/UITraitCollection/init(displayScale:))

Creates a trait collection that contains only a specified display scale.

[`init(displayGamut:)`](/documentation/UIKit/UITraitCollection/init(displayGamut:))

Creates a trait collection that contains only the specified display gamut trait.

[`init(layoutDirection:)`](/documentation/UIKit/UITraitCollection/init(layoutDirection:))

Creates a trait collection that contains only the specified layout direction trait.

[`init(preferredContentSizeCategory:)`](/documentation/UIKit/UITraitCollection/init(preferredContentSizeCategory:))

Creates a trait collection that contains only the specified content size category trait.

[`init(activeAppearance:)`](/documentation/UIKit/UITraitCollection/init(activeAppearance:))

Creates a trait collection that contains only the specified active appearance trait.

[`init(toolbarItemPresentationSize:)`](/documentation/UIKit/UITraitCollection/init(toolbarItemPresentationSize:))

Creates a trait collection that contains only the specified toolbar item presentation size trait.

[`init(hdrHeadroomUsageLimit:)`](/documentation/UIKit/UITraitCollection/init(hdrHeadroomUsageLimit:)-5zqph)

[`init(imageDynamicRange:)`](/documentation/UIKit/UITraitCollection/init(imageDynamicRange:))

Construct a new trait collection with the given image content dynamic range.

[`init(listEnvironment:)`](/documentation/UIKit/UITraitCollection/init(listEnvironment:))

Construct a new trait collection with the given `listEnvironment`.

[`init(resolvesNaturalAlignmentWithBaseWritingDirection:)`](/documentation/UIKit/UITraitCollection/init(resolvesNaturalAlignmentWithBaseWritingDirection:))

[`init(sceneCaptureState:)`](/documentation/UIKit/UITraitCollection/init(sceneCaptureState:))

Construct a new trait collection with the given scene capture state.

[`init(tabAccessoryEnvironment:)`](/documentation/UIKit/UITraitCollection/init(tabAccessoryEnvironment:))

Constructs a new trait collection with the given `tabAccessoryEnvironment`.

[`init(typesettingLanguage:)`](/documentation/UIKit/UITraitCollection/init(typesettingLanguage:))

[`init(coder:)`](/documentation/UIKit/UITraitCollection/init(coder:))

Creates a trait collection from data in an unarchiver.

[`init(traitsFrom:)`](/documentation/UIKit/UITraitCollection/init(traitsFrom:))

Creates a trait collection that consists of traits merged from a specified array of trait collections.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)