Class

UIImageAsset

A container for a collection of images that represent multiple ways of describing a single piece of artwork.

Declaration

@interface UIImageAsset : NSObject

Overview

A common use case for UIImageAsset is the grouping of multiple images of the same item at different display scales. Image asset objects are not assigned to instances of UIImage rather; UIImage provides an asset when multiple representations of an image are available. Images retrieved from image asset catalogs using the imageNamed: or imageNamed:inBundle:compatibleWithTraitCollection: methods automatically have an image asset object that allows access to other images from the catalog.

Registering an Image

When you register an image with an image asset, you associate a UITraitCollection object with the image. The trait collection must contain the displayScale and userInterfaceIdiom trait properties. If you do not define these traits in the trait collection, the following defaults are assigned:

For example, if you create a trait collection that only contains a horizontal size class, the default display scale and idiom are added when the image is registered.

Retrieving an Image

When you retrieve or unregister an image from an image asset, you do so using the trait collection that was used to register the image. To ensure the correct image is retrieved, the trait collection used must contain the displayScale and userInterfaceIdiom traits. If these traits are not defined in the trait collection, the following defaults are assigned:

For example, if you create a trait collection that only contains a horizontal size class, the default display scale and idiom of the current device are added when searching the UIImageAsset for an image.

UIImageView automatically retrieves the correct image when traitCollectionDidChange: is called on it.

Topics

Initializing an Image Asset

- init

Creates a new image asset object.

Registering and Unregistering Images

- registerImage:withTraitCollection:

Register an image with the specified trait collection.

- registerImage:withConfiguration:

Registers an image with the specified image configuration details.

- unregisterImageWithTraitCollection:

Unregisters the image with the specified trait collection from the image asset.

- unregisterImageWithConfiguration:

Unregisters the image with the specified image configuration details from the image asset.

Retrieving an Image from an Image Asset

- imageWithTraitCollection:

Returns the variant of the image that best matches the specified trait collection.

- imageWithConfiguration:

Returns the variant of the image that best matches the specified image configuration details.

Relationships

Inherits From

Conforms To

See Also

Assets

NSDataAsset

An object from a data set type stored in an asset catalog.