Skip to content

Instantly share code, notes, and snippets.

@asarode
Created January 10, 2015 07:36
Show Gist options
  • Save asarode/831eca167d708b2557bc to your computer and use it in GitHub Desktop.
Save asarode/831eca167d708b2557bc to your computer and use it in GitHub Desktop.
Swift extension to get luma value of a UIColor
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