UIColor

public extension UIColor

A set of extensions to the UIColor class. This mostly has ways of inspecting the color.

Convenience Initializers

Color Information Instance Computed Properties

  • Declaration

    Swift

    var hexValue: String { get }

    Return Value

    the color, as an RGBA hex value in a String, prefixed by a hash sign (“#RRGGBBAA”).

  • Declaration

    Swift

    var isClear: Bool { get }

    Return Value

    true, if the color is clear.

  • Declaration

    Swift

    var isMonochrome: Bool { get }

    Return Value

    True, if the color is monochrome (has no hue).

  • This just allows us to get an RGB color from a standard UIColor.

    Declaration

    Swift

    var rgba: (r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat) { get }

    Return Value

    A tuple, containing the RGBA color.

  • This just allows us to get an HSB color from a standard UIColor. From This SO Answer

    Declaration

    Swift

    var hsba: (h: CGFloat, s: CGFloat, b: CGFloat, a: CGFloat) { get }

    Return Value

    A tuple, containing the HSBA color.

  • Returns the inverted color. NOTE: This is quite primitive, and may not return exactly what may be expected. From This SO Answer

    Declaration

    Swift

    var inverted: UIColor { get }

Color Computation Instance Methods

  • This will return an intermediate color, between this color, and another one.

    This was inspired by this SO answer

    Declaration

    Swift

    func intermediateColor(otherColor inColor: UIColor, samplePoint inSamplePoint: CGFloat = 0.5, isHSL inIsHSL: Bool = true) -> UIColor

    Parameters

    otherColor

    The other end of the color spectrum we are testing.

    samplePoint

    Optional (default is 50%). The distance betweeen 0 (this color), and 1 (otherColor).

    isHSL

    Optional (default is true). If true, then the intermediate color is determined via HSL. If false, we use RGB.

    Return Value

    the intermediate color.