Skip to content

Commit

Permalink
feat: dynamic color helper
Browse files Browse the repository at this point in the history
  • Loading branch information
gtokman committed May 3, 2021
1 parent d094b50 commit 5e11862
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Sources/ExtensionKit/UIKit/UIColor.swift
Expand Up @@ -77,6 +77,21 @@ public extension UIColor {
return self.adjust(by: -1 * abs(percentage) )
}

/// Color for UI appearance ex: dark/light mode
/// - Parameters:
/// - light: Light Color
/// - dark: Dark Color
/// - Returns: UIColor
static func dynamicColor(light: UIColor, dark: UIColor) -> UIColor {
UIColor { traitCollection -> UIColor in
if traitCollection.userInterfaceStyle == .dark {
return dark
} else {
return light
}
}
}

private func adjust(by percentage: CGFloat = 30.0) -> UIColor {
var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0
if self.getRed(&red, green: &green, blue: &blue, alpha: &alpha) {
Expand Down

0 comments on commit 5e11862

Please sign in to comment.