In macOS 10.14 users can choose to adopt a system-wide light or dark appearance and I need to adjust some colours manually depend of the current mode.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- back button text does not change
- iOS (objective-c) compression_decode_buffer() retu
- how to find the index position of the ARRAY Where
相关文章
- 现在使用swift开发ios应用好还是swift?
- Visual Studio Code, MAC OS X, OmniSharp server is
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- IntelliJ IDEA can't open projects or add SDK o
- Automator: How do I use the Choose from List actio
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
Swift 4
UPDATE:
Since the actual appearance object you usually get via
effectiveAppearance
is a composite appearance, asking for its name directly probably isn't a reliable solution.Asking for the
currentAppearance
usually isn't a good idea, either, as a view may be explicitly set to light mode or you want to know whether a view is light or dark outside of adrawRect:
where you might get incorrect results after a mode switch.The solution I came up with looks like this:
You would use it like
appearanceIsDark(someView.effectiveAppearance)
since the appearance of a specific view may be different than that of another view if you explicitly setsomeView.appearance
.You could also create a category on
NSAppearance
and add a- (BOOL)isDark
method to getsomeView.effectiveAppearance.isDark
(better chose a name that is unlikely to be used by Apple in the future, e.g. by adding a vendor prefix).I have used the current appearance checking if the system is 10.14
And to detect the change of mode in a view the methods are:
And to detect the change of mode in a view controller the methods are:
Using notification:
For more information Dark Mode Documentation