How do I check weather Im in Dark Mode or not in UIKit

How in UIKit do i tell if the user is in dark mode or not

Accepted Reply

The viewcontroller has a traitCollection and you can query its userInterfaceStyle.

if  traitCollection.userInterfaceStyle == .light {
//light mode
}

Replies

You can check this property:

UITraitCollection.userInterfaceStyle


For a detailed explanation: https://schiavo.me/2019/implementing-dark-mode/

The viewcontroller has a traitCollection and you can query its userInterfaceStyle.

if  traitCollection.userInterfaceStyle == .light {
//light mode
}