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
/// An extension to derive web safe colors. | |
extension UIColor { | |
/// The nearest web safe color to the current color. All web safe colors have RGB | |
/// component values of 0, 51, 102, 153, 204, or 255 (20% intervals). | |
var webSafe: UIColor { | |
var (r, g, b, a) = (CGFloat(), CGFloat(), CGFloat(), CGFloat()) | |
getRed(&r, green: &g, blue: &b, alpha: &a) | |
let clusters: [CGFloat] = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0] |
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
/// An extension to provide conversion to and from Y′IQ colors. | |
extension UIColor { | |
/// The Y′IQ components of a color - luma (Y′) and chroma (I,Q). | |
struct YIQ: Hashable { | |
/// The luma component of the color, in the range [0, 1] (black to white). | |
var Y: CGFloat | |
/// The orange-blue chroma component of the color, in the range [-0.596, 0.596]. | |
var I: CGFloat |
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
/// An extension to provide conversion to and from Y′UV colors. | |
extension UIColor { | |
/// The Y′UV components of a color - luma (Y′) and chroma (U,V). | |
struct YUV: Hashable { | |
/// The luma component of the color, in the range [0, 1] (black to white). | |
var Y: CGFloat | |
/// The blue-difference chroma component of the color, in the range [-0.436, 0.436]. | |
var U: CGFloat |
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
/// An extension to provide conversion to and from HSI (hue, saturation, intensity) colors. | |
extension UIColor { | |
/// The HSI (hue, saturation, intensity) components of a color. | |
struct HSI: Hashable { | |
/// The hue component of the color, in the range [0, 360°]. | |
var hue: CGFloat | |
/// The saturation component of the color, in the range [0, 100%]. | |
var saturation: CGFloat |
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
/// An extension to provide conversion to and from Y′PbPr colors. | |
extension UIColor { | |
/// The Rec.601 (standard-definition) coefficients used to calculate luma. | |
private static let encoding: (r: CGFloat, g: CGFloat, b: CGFloat) = (0.299, 0.587, 0.114) | |
/// The Y′PbPr components of a color - luma (Y′) and chroma (Pb,Pr). | |
struct YPbPr: Hashable { | |
/// The luma component of the color, in the range [0, 1] (black to white). |
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
/// An extension to provide conversion to and from linear RGB colors. | |
extension UIColor { | |
/// A set of non-gamma corrected linear RGB values, in the range [0, 1]. | |
typealias LinearRGB = (r: CGFloat, g: CGFloat, b: CGFloat) | |
/// The inverse companded sRGB components to get non-gamma corrected linear values, | |
/// in the range [0, 1]. | |
var linearRGB: LinearRGB { | |
var (r, g, b) = (CGFloat(), CGFloat(), CGFloat()) |
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
/// An extension to provide conversion to and from CIELCh° colors. | |
extension UIColor { | |
/// The CIELCh° components of a color - lightness (L), chroma (C), and hue (h). | |
struct CIELCh: Hashable { | |
/// The lightness component of the color, in the range [0, 100] (darkest to brightest). | |
var L: CGFloat | |
/// The chroma component of the color. | |
var C: CGFloat |
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
/// An extension to provide conversion to and from CIELUV colors. | |
extension UIColor { | |
/// The CIELUV components of a color - lightness (L) and chromaticity (u,v). | |
struct CIELUV: Hashable { | |
/// The lightness component of the color, in the range [0, 100] (darkest to brightest). | |
var L: CGFloat | |
/// The green-red chromaticity component of the color, typically in the range [-100, 100]. | |
var u: CGFloat |
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
/// An extension to traverse the responder chain for the nearest parent view controller. | |
extension UIView { | |
/// The nearest parent view controller in the responder chain. | |
var parentViewController: UIViewController? { | |
if let nextResponder = self.next as? UIViewController { | |
return nextResponder | |
} else if let nextResponder = self.next as? UIView { | |
return nextResponder.parentViewController | |
} else { |
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
/// An extension to provide conversion to and from Hunter Lab colors. | |
extension UIColor { | |
/// XYZ tristimulus values of d65 illuminant with standard 2° observer. | |
private static let d65: (X: CGFloat, Y: CGFloat, Z: CGFloat) = (95.047, 100.000, 108.883) | |
/// The Hunter Lab components of a color - lightness (L) and chromaticity (a,b). | |
struct HunterLab: Hashable { | |
/// The lightness component of the color, in the range [0, 100] (darkest to brightest). |
NewerOlder