PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 29, 2022

[FIXED] How to check if Dark Appearance is enabled tvOS

 September 29, 2022     swift, tvos, tvos10     No comments   

Issue

How do I check if a user has enabled Dark Appearance on their Apple TV?


Solution

Using UIUserInterfaceStyle, first available in tvOS 10, we can check what appearance the user has set.

For example:

func checkInterfaceStyle() {
    guard(traitCollection.responds(to: #selector(getter: UITraitCollection.userInterfaceStyle)))
        else { return }

    let style = traitCollection.userInterfaceStyle

    switch style {
    case .light:
        print("light")
    case .dark:
        print("dark")
    case .unspecified:
        print("unspecified")
    }
}

Also, if you're updating from an Xcode 7/tvOS 9.0 project you will need to include UIUserInterfaceStyle in your info.plist. New projects created with Xcode 8 already have this key included.

enter image description here

<key>UIUserInterfaceStyle</key>
    <string>Automatic</string>


Answered By - Daniel Storm
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing