Search code examples
swiftuilabeltvosuivibrancyeffect

How can I make a UILabel's text style adapt to the blurred background in tvOS?


I want to create a UILabel that adapts to the blurred background of a tvOS application, like on this image from a system function. Note how the text looks brownish and how it blends in with the background - I want to achieve the same effect. Is it possible to do with a public API?

Text with adapted design in tvOS


Solution

  • This is achievable with two nested UIVisualEffectViews. You should apply a UIBlurEffect to the parent and add a UIVibrancyEffect to the child. It pretty much works in the same way as it does on iOS.

    You can achieve this in Interface Builder by using Visual Effect Views with Blur and Vibrancy, which creates the following view structure:

    Visual Effect Views with Blur and Vibrancy - view structure

    You can also create this effect programmatically with this approach.