-
-
Save soffes/67fc0c03b03f1d773357 to your computer and use it in GitHub Desktop.
Swift extension to get luma value of a UIColor
This file contains 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
import UIKit | |
extension UIColor { | |
var luminance: CGFloat { | |
var red: CGFloat = 0 | |
var green: CGFloat = 0 | |
var blue: CGFloat = 0 | |
getRed(&red, green: &green, blue: &blue, alpha: nil) | |
return (0.2126 * red) + (0.7152 * green) + (0.0722 * blue) | |
} | |
var isLight: Bool { | |
return luminance >= 0.6 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment