Starting from iOS/iPadOS 13, a dark user interface style is available, similar to the dark mode introduced in macOS Mojave. How can I check whether the user has enabled the system-wide dark mode?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
1/ for UIView/UIViewController:
2/ for static or other:
BUT:
Create a class function for write method 1 time and use everywhere you want
Objective C
To detect when dark mode is enabled or disabled via the Control Centre use an "appDidBecomeActive" notification that will be triggered when you return to your app.
Don't forget to remove it when you're finished:
Do what ever you need to when dark mode changes:
You can use this extension:
As mentioned by daveextreme, checking the current view user interface style doesn't always return the system style when you use the
overrideUserInterfaceStyle
property. In such cases it may be better to use the following code:You should check the
userInterfaceStyle
variable ofUITraitCollection
, same as on tvOS and macOS.You should use the
traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?)
function ofUIView
/UIViewController
to detect changes in the interface environment (including changes in the user interface style).From Apple Developer Documentation:
System default UI elements (such as
UITabBar
orUISearchBar
) automatically adapt to the new user interface style.