I know there is a way to programmatically override the interface style in iOS like below:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
overrideUserInterfaceStyle = .dark
}
}
Howover, I tried searching for something similar in macOS but not able to find one. Is there a way to achieve this in macOS?
It can be done via
public protocol NSAppearanceCustomization : NSObjectProtocol {
@available(OSX 10.9, *)
var appearance: NSAppearance? { get set }
The NSApplication
, NSWindow
, and NSView
conform to this protocol, so you can use it like
window.appearance = NSAppearance(named: .aqua)
window.makeKeyAndOrderFront(nil)
I found it finally. You can do the same in macOS like below:
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
view.appearance = NSAppearance(named: .darkAqua)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With