How to load a resource depending on UIUserInterfaceStyle

Say I have a TVML app where I have implemented a custom placeholder like so:

<img style="tv-placeholder: my-placeholder" />


and my custom interface creator:

class MyExtendedInterfaceCreator: NSObject, TVInterfaceCreating {
    override init() {
        super.init()
    }
    
    func resourceImage(name resourceName: String) -> UIImage? {
        if resourceName == "my-placeholder" {
            return UIImage(named: "placeholders/my-placeholder")
        }
        
        return nil
    }
}


How do I change this code such that I can return a different placeholder if the UIUserInterfaceStyle is 'light' or 'dark'?

Accepted Reply

You will need to setup media queries to switch the placeholder names when in different themes:


https://developer.apple.com/library/content/documentation/LanguagesUtilities/Conceptual/ATV_Template_Guide/TVMLQueries.html#//apple_ref/doc/uid/TP40015064-CH47-SW2

Replies

You will need to setup media queries to switch the placeholder names when in different themes:


https://developer.apple.com/library/content/documentation/LanguagesUtilities/Conceptual/ATV_Template_Guide/TVMLQueries.html#//apple_ref/doc/uid/TP40015064-CH47-SW2

I had a feeling that'd be the case and was hoping for a more automated solution. Thanks for confirming.