Skip to content

Commit

Permalink
Update UIColor+Hue.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
lukepistrol authored May 13, 2019
1 parent 49c81b7 commit 6edfec2
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions Source/iOS+tvOS/UIColor+Hue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public extension UIColor {
///
/// - Parameter minSaturation: The minimun saturation value
/// - Returns: The adjusted color
public func color(minSaturation: CGFloat) -> UIColor {
func color(minSaturation: CGFloat) -> UIColor {
var (hue, saturation, brightness, alpha): (CGFloat, CGFloat, CGFloat, CGFloat) = (0.0, 0.0, 0.0, 0.0)
getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha)

Expand All @@ -49,7 +49,7 @@ public extension UIColor {
///
/// - Parameter value: The alpha value
/// - Returns: The alpha adjusted color
public func alpha(_ value: CGFloat) -> UIColor {
func alpha(_ value: CGFloat) -> UIColor {
return withAlphaComponent(value)
}
}
Expand All @@ -58,7 +58,7 @@ public extension UIColor {

public extension UIColor {

public func hex(hashPrefix: Bool = true) -> String {
func hex(hashPrefix: Bool = true) -> String {
var (r, g, b, a): (CGFloat, CGFloat, CGFloat, CGFloat) = (0.0, 0.0, 0.0, 0.0)
getRed(&r, green: &g, blue: &b, alpha: &a)

Expand All @@ -74,27 +74,27 @@ public extension UIColor {
return [r, g, b]
}

public var isDark: Bool {
var isDark: Bool {
let RGB = rgbComponents()
return (0.2126 * RGB[0] + 0.7152 * RGB[1] + 0.0722 * RGB[2]) < 0.5
}

public var isBlackOrWhite: Bool {
var isBlackOrWhite: Bool {
let RGB = rgbComponents()
return (RGB[0] > 0.91 && RGB[1] > 0.91 && RGB[2] > 0.91) || (RGB[0] < 0.09 && RGB[1] < 0.09 && RGB[2] < 0.09)
}

public var isBlack: Bool {
var isBlack: Bool {
let RGB = rgbComponents()
return (RGB[0] < 0.09 && RGB[1] < 0.09 && RGB[2] < 0.09)
}

public var isWhite: Bool {
var isWhite: Bool {
let RGB = rgbComponents()
return (RGB[0] > 0.91 && RGB[1] > 0.91 && RGB[2] > 0.91)
}

public func isDistinct(from color: UIColor) -> Bool {
func isDistinct(from color: UIColor) -> Bool {
let bg = rgbComponents()
let fg = color.rgbComponents()
let threshold: CGFloat = 0.25
Expand All @@ -112,7 +112,7 @@ public extension UIColor {
return result
}

public func isContrasting(with color: UIColor) -> Bool {
func isContrasting(with color: UIColor) -> Bool {
let bg = rgbComponents()
let fg = color.rgbComponents()

Expand All @@ -131,7 +131,7 @@ public extension UIColor {

public extension Array where Element : UIColor {

public func gradient(_ transform: ((_ gradient: inout CAGradientLayer) -> CAGradientLayer)? = nil) -> CAGradientLayer {
func gradient(_ transform: ((_ gradient: inout CAGradientLayer) -> CAGradientLayer)? = nil) -> CAGradientLayer {
var gradient = CAGradientLayer()
gradient.colors = self.map { $0.cgColor }

Expand Down Expand Up @@ -196,7 +196,7 @@ public extension UIColor {
public extension UIColor {

/**adds hue, saturation, and brightness to the HSB components of this color (self)*/
public func add(hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat) -> UIColor {
func add(hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat) -> UIColor {
var (oldHue, oldSat, oldBright, oldAlpha) : (CGFloat, CGFloat, CGFloat, CGFloat) = (0,0,0,0)
getHue(&oldHue, saturation: &oldSat, brightness: &oldBright, alpha: &oldAlpha)

Expand All @@ -213,7 +213,7 @@ public extension UIColor {
}

/**adds red, green, and blue to the RGB components of this color (self)*/
public func add(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) -> UIColor {
func add(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) -> UIColor {
var (oldRed, oldGreen, oldBlue, oldAlpha) : (CGFloat, CGFloat, CGFloat, CGFloat) = (0,0,0,0)
getRed(&oldRed, green: &oldGreen, blue: &oldBlue, alpha: &oldAlpha)
// make sure new values doesn't overflow
Expand All @@ -224,24 +224,24 @@ public extension UIColor {
return UIColor(red: newRed, green: newGreen, blue: newBlue, alpha: newAlpha)
}


public func add(hsb color: UIColor) -> UIColor {
func add(hsb color: UIColor) -> UIColor {
var (h,s,b,a) : (CGFloat, CGFloat, CGFloat, CGFloat) = (0,0,0,0)
color.getHue(&h, saturation: &s, brightness: &b, alpha: &a)
return self.add(hue: h, saturation: s, brightness: b, alpha: 0)
}
public func add(rgb color: UIColor) -> UIColor {

func add(rgb color: UIColor) -> UIColor {
return self.add(red: color.redComponent, green: color.greenComponent, blue: color.blueComponent, alpha: 0)
}

public func add(hsba color: UIColor) -> UIColor {
func add(hsba color: UIColor) -> UIColor {
var (h,s,b,a) : (CGFloat, CGFloat, CGFloat, CGFloat) = (0,0,0,0)
color.getHue(&h, saturation: &s, brightness: &b, alpha: &a)
return self.add(hue: h, saturation: s, brightness: b, alpha: a)
}

/**adds the rgb components of two colors*/
public func add(rgba color: UIColor) -> UIColor {
func add(rgba color: UIColor) -> UIColor {
return self.add(red: color.redComponent, green: color.greenComponent, blue: color.blueComponent, alpha: color.alphaComponent)
}
}

0 comments on commit 6edfec2

Please sign in to comment.