Color

public typealias Color = UIKit.UIColor
  • Mechanica

    Returns the hexadecimal string representation of self in the sRGB space.

    Example:

    Color.red.hexString ->"#FF0000"
    Color.black.hexString -> "#000000"
    Color.gray.hexString -> "#7F7F7F"
    Color.green.hexString -> "#00FF00"
    

    Declaration

    Swift

    public final var hexString: String? { get }
  • Mechanica

    Initializes and returns a random color object in the sRGB space.

    Declaration

    Swift

    public class func random(randomAlpha: Bool = false) -> Self
  • Mechanica

    Alias for RGBA color space components

    Declaration

    Swift

    public typealias RGBA = (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat)
  • Mechanica

    Returns the color’s RGBA components as Ints.

    Declaration

    Swift

    public final var rgbaComponents: (red: Int, green: Int, blue: Int, alpha: Int)? { get }
  • Mechanica

    Returns the color’s RGBA components as a tuple of CGFloat.

    Declaration

    Swift

    public final var rgba: RGBA? { get }
  • Mechanica

    Creates a new color in the sRGB color space (if needed) guard letthat matches (or closely approximates) the current color. Although the new color might have different component values, it looks the same as the original.

    Declaration

    Swift

    public final func convertedToCompatibleSRGBColor() -> Color?
  • Mechanica

    Returns a sRGB color from a hexadecimal integer.

    Example:

    Color(hex: 0xFF0000)
    Color(hex: 0xFF0000, alpha: 0.5)
    

    Declaration

    Swift

    public convenience init(hex: UInt32, alpha: CGFloat = 1)

    Parameters

    hex

    The hex component of the color object, specified as a value from 0x000000 to 0xFFFFFF

    alpha

    The opacity component of the color object, specified as a value from 0.0 to 1.0 (optional).

  • Mechanica

    Creates and returns an Color object given an hex color string.

    Note

    Supported formats: RGB, #RGB, RGBA, #RGBA, RRGGBB, #RRGGBB, RRGGBBAA, #RRGGBBAA).

    Declaration

    Swift

    public convenience init?(hexString: String)

    Parameters

    hexString

    The hex color string (e.g.: #551a8b, 551a8b, 551A8B, #FFF).

  • Mechanica

    Alias for HSBA color space components

    Declaration

    Swift

    public typealias HSBA = (hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat)
  • Mechanica

    Returns the components that make up the color in the HSBA color space.

    Declaration

    Swift

    public final var hsba: HSBA? { get }
  • Mechanica

    Blends two colors together.

    Note

    The sum of the two percentages must be 1.0 otherwise the blendind operation is not executed.

    Declaration

    Swift

    public static func blend(_ firstColor: Color, percentage firstPercentage: CGFloat = 0.5, with secondColor: Color, percentage secondPercentage: CGFloat = 0.5) -> Color?

    Parameters

    firstColor

    First color to blend.

    firstPercentage

    Intensity of first color (default is 0.5)

    secondColor

    Second color to blend.

    secondPercentage

    Intensity of second color (default is 0.5)

    Return Value

    a new color blending the two colors.