Created
January 10, 2015 07:36
-
-
Save asarode/831eca167d708b2557bc 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 { | |
func isLightColor() -> Bool { | |
var red : CGFloat = 0 | |
var green : CGFloat = 0 | |
var blue : CGFloat = 0 | |
self.getRed(&red, green: nil, blue: nil, alpha: nil) | |
self.getRed(nil, green: &green, blue: nil, alpha: nil) | |
self.getRed(nil, green: nil, blue: &blue, alpha: nil) | |
let lumaRed = 0.2126 * Float(red) | |
let lumaGreen = 0.7152 * Float(green) | |
let lumaBlue = 0.0722 * Float(blue) | |
let luma = Float(lumaRed + lumaGreen + lumaBlue) | |
return luma >= 0.6 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment