Skip to content

Instantly share code, notes, and snippets.

@soffes
Forked from asarode/UIColorExtension.swift
Created July 21, 2015 15:48
Show Gist options
  • Save soffes/67fc0c03b03f1d773357 to your computer and use it in GitHub Desktop.
Save soffes/67fc0c03b03f1d773357 to your computer and use it in GitHub Desktop.
Swift extension to get luma value of a UIColor
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