Responding to Changing Display Modes on Apple TV

Change images and resources dynamically when the screen gamut on your device changes.


On Apple TV (5th generation), the assets required for an app depend on the screen gamut of the TV being used, with 4K TVs using the Display P3 gamut, and all other resolutions using the sRGB gamut. Also, the screen gamut of the TV can change at any time, switching between 4K and other resolutions. Your app needs to respond to these changes and present the appropriate assets when required.

Create and Place the Image Assets

In Xcode, create an image asset in an asset catalog. In the Attributes inspector, configure the asset catalog to handle Display P3 images. In the Devices pane, ensure that Apple TV is selected. From the Gamut menu, select sRGB and Display P3. Figure 1 shows the correct settings.

Figure 1

Asset catalog configuration for sRGB and Display P3 image support

Add Images to the Asset Catalog

Place non-4K images in the 1x (sRGB) slot and 4K images in the 2x (Display P3) slot. The correct image is automatically loaded based on the display gamut of the TV. Figure 2 shows assets placed in their correct containers.

Figure 2

Adding assets

Adapt to Screen Changes Programmatically

Implement the traitCollectionDidChange(_:) method to respond to changing device traits. If your app performs expensive operations related to image generation based on the current display gamut, it's important to verify that the display gamut has changed before performing these operations. Listing 1 shows how to test whether the display gamut changed.

Listing 1

Testing for a changing screen resolution

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
    let currentDisplayGamut = self.traitCollection.displayGamut
    if (previousTraitCollection?.displayGamut == .SRGB) && (currentDisplayGamut == .SRGB) {
        // Resolution didn't change. Your code goes here.
    } else if (previousTraitCollection?.displayGamut == .P3) && (currentDisplayGamut == .P3) {
        // Resolution didn't change. Your code goes here.
    } else {
        // Resolution changed. Your code goes here.

See Also

Device Environment

class UIDevice

A representation of the current device.

class UITraitCollection

The iOS interface environment for your app, defined by traits such as horizontal and vertical size class, display scale, and user interface idiom.

protocol UITraitEnvironment

A collection of methods that makes the iOS interface environment available to your app.

protocol UIAdaptivePresentationControllerDelegate

A set of methods that, in conjunction with a presentation controller, determine how to respond to trait changes in your app.