Skip to content

Commit

Permalink
Statically define the accent color so that it doesn't regularly do th…
Browse files Browse the repository at this point in the history
…e lookup
  • Loading branch information
vincode-io committed Mar 8, 2024
1 parent ffef0ca commit 4a7dfbc
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions VinUtility/Sources/VinUtility/UIColor+VU.swift
Expand Up @@ -7,16 +7,18 @@
import UIKit

public extension UIColor {


static var definedAccentColor = UIColor(named: "AccentColor")!

static var accentColor: UIColor {
guard let systemHighlightColor = UserDefaults.standard.string(forKey: "AppleHighlightColor"),
let colorName = systemHighlightColor.components(separatedBy: " ").last else { return UIColor(named: "AccentColor")! }
let colorName = systemHighlightColor.components(separatedBy: " ").last else { return .definedAccentColor }

guard colorName != "Graphite" else { return UIColor.systemGray }

let selector = NSSelectorFromString(NSString.localizedStringWithFormat("system%@Color", colorName) as String)
guard UIColor.responds(to: selector) else { return UIColor(named: "AccentColor")! }
return UIColor.perform(selector).takeUnretainedValue() as? UIColor ?? UIColor(named: "AccentColor")!
return UIColor.perform(selector).takeUnretainedValue() as? UIColor ?? .definedAccentColor
}

var isDefaultAccentColor: Bool {
Expand Down

0 comments on commit 4a7dfbc

Please sign in to comment.