Created
October 20, 2019 06:10
-
-
Save JunyuKuang/3ecc7c9374c0ba67438c9a6d06612e36 to your computer and use it in GitHub Desktop.
Access accent color from Mac Catalyst app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// UIKitAccentColor | |
// | |
// Created by Jonny Kuang on 10/20/19. | |
// Copyright © 2019 Jonny Kuang. All rights reserved. | |
// | |
import UIKit | |
class ViewController: UIViewController { | |
#if targetEnvironment(macCatalyst) | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
view.backgroundColor = .kjy_controlAccentColor | |
NotificationCenter.default.addObserver(self, selector: #selector(systemColorsDidChange), name: .init("NSSystemColorsDidChangeNotification"), object: nil) | |
} | |
@objc private func systemColorsDidChange() { | |
print(#function) | |
view.backgroundColor = .kjy_controlAccentColor | |
} | |
#endif | |
} | |
extension UIColor { | |
#if targetEnvironment(macCatalyst) | |
static var kjy_controlAccentColor: UIColor! { UIColor.value(forKey: "controlAccentColor") as? UIColor } | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment