Skip to content

Instantly share code, notes, and snippets.

@JunyuKuang
Created October 20, 2019 06:10
Show Gist options
  • Save JunyuKuang/3ecc7c9374c0ba67438c9a6d06612e36 to your computer and use it in GitHub Desktop.
Save JunyuKuang/3ecc7c9374c0ba67438c9a6d06612e36 to your computer and use it in GitHub Desktop.
Access accent color from Mac Catalyst app
//
// 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