Initializer

init(traitsFrom:)

Returns a new trait collection consisting of traits merged from a specified array of trait collections.

Declaration

init(traitsFrom traitCollections: [UITraitCollection])

Parameters

traitCollections

An array of UITraitCollection objects.

Return Value

A new trait collection consisting of traits merged from a specified traitCollections array.

Discussion

This method takes an array of one or more trait collections and merges them to create a new trait collection. If the array contains more than one element, the highest-indexed element that contains a given trait is used for that trait. For example, the following code snippet creates a trait collection with a compact horizontal size class, because the second element in the array overrides the first for that trait:

UITraitCollection *newHorizontalSizeClass1 = [UITraitCollection traitCollectionWithHorizontalSizeClass: UIUserInterfaceSizeClassRegular];
UITraitCollection *newHorizontalSizeClass2 = [UITraitCollection traitCollectionWithHorizontalSizeClass: UIUserInterfaceSizeClassCompact];
NSArray *traitArray = [NSArray arrayWithObjects: newHorizontalSizeClass1, newHorizontalSizeClass2, nil];
UITraitCollection *combinedTraits = [UITraitCollection traitCollectionWithTraitsFromCollections: traitArray];

See Also

Creating a Trait Collection

init()

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

init(userInterfaceIdiom: UIUserInterfaceIdiom)

Returns a new trait collection containing only a specified interface idiom.

init(horizontalSizeClass: UIUserInterfaceSizeClass)

Returns a new trait collection containing only a specified horizontal size class.

init(verticalSizeClass: UIUserInterfaceSizeClass)

Returns a new trait collection containing only a specified vertical size class.

init(forceTouchCapability: UIForceTouchCapability)

Creates a trait collection containing only a specified force touch capability trait.

init(displayScale: CGFloat)

Returns a new trait collection containing only a specified display scale.

init(displayGamut: UIDisplayGamut)

Returns a new trait collection containing only the specified display gamut trait.

init(layoutDirection: UITraitEnvironmentLayoutDirection)

Returns a new trait collection containing only the specified layout direction trait.

init(preferredContentSizeCategory: UIContentSizeCategory)

Returns a new trait collection containing only the specified content size category trait.

init(userInterfaceStyle: UIUserInterfaceStyle)

Returns a new trait collection containing only the specified user interface style trait.