Skip to content

Instantly share code, notes, and snippets.

@JunyuKuang
Created October 20, 2019 06:10
Show Gist options
  • Select an option

  • Save JunyuKuang/3ecc7c9374c0ba67438c9a6d06612e36 to your computer and use it in GitHub Desktop.

Select an option

Save JunyuKuang/3ecc7c9374c0ba67438c9a6d06612e36 to your computer and use it in GitHub Desktop.

Revisions

  1. JunyuKuang created this gist Oct 20, 2019.
    33 changes: 33 additions & 0 deletions AccentColorDemo.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    //
    // 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
    }