UIColor

extension UIColor
  • Returns a UIColor from the given hexidecimal integer.

    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).

    Return Value

    A UIColor initialized with the given color value.

  • Returns a UIColor from a hue-saturation-lightness (HSL) set.

    Declaration

    Swift

    public convenience init(hue: CGFloat, saturation: CGFloat, lightness: CGFloat, alpha: CGFloat = 1)

    Parameters

    hue

    The hue component of the color object, specified as a value from 0.0 to 1.0.

    saturation

    The saturation component of the color object, specified as a value from 0.0 to 1.0.

    lightness

    The lightness component of the color object, specified as a value from 0.0 to 1.0.

    alpha

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

    Return Value

    A UIColor initialized with the given color value.

  • Returns a UIColor from a cyan-magenta-yellow-key (CMYK) set.

    Declaration

    Swift

    public convenience init(cyan: CGFloat, magenta: CGFloat, yellow: CGFloat, key: CGFloat, alpha: CGFloat = 1)

    Parameters

    cyan

    The cyan component of the color object, specified as a value from 0.0 to 1.0.

    magenta

    The magenta component of the color object, specified as a value from 0.0 to 1.0.

    yellow

    The yellow component of the color object, specified as a value from 0.0 to 1.0.

    key

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

    alpha

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

    Return Value

    A UIColor initialized with the given color value.

  • Returns a UIColor from a given hex color string.

    Declaration

    Swift

    public convenience init(hexString: String, alpha: CGFloat = 1)

    Parameters

    hexString

    The hex color string, e.g.: #9443FB or 9443FB.

    Return Value

    A UIColor initialized with the color specified by the hexString.

  • Returns a UIColor initialized with color components divided by 255.0.

    Declaration

    Swift

    public convenience init(red: UInt8, green: UInt8, blue: UInt8)

    Parameters

    red

    Integer representation of the red component in range of 0-255.

    green

    Integer representation of the green component in range of 0-255.

    blue

    Integer representation of the blue component in range of 0-255.

  • Returns a random UIColor with hue, saturation, and brightness ranging from 0.5 to 1.0.

    Declaration

    Swift

    public static var random: UIColor { get }
  • Lightens the given color by the given percentage.

    Declaration

    Swift

    public final func lightened(by amount: CGFloat) -> UIColor

    Parameters

    amount

    The percentage by which to lighten the color. Valid values are from 0.0 to 1.0, or for a more readable format 0% to 100%.

    Return Value

    The lightened color.

  • Darkens the given color by the given percentage.

    Declaration

    Swift

    public final func darkened(by amount: CGFloat) -> UIColor

    Parameters

    amount

    The percentage by which to darken the color. Valid values are from 0.0 to 1.0, or for a more readable format 0% to 100%.

    Return Value

    The darkened color.

  • Returns the color represenation as a hexadecimal string, prefixed with ‘#’.

    Declaration

    Swift

    public final var hexString: String { get }

    Return Value

    The hexadecimal string representation of the color.

  • hex

    Returns the color representation as a 32-bit integer.

    Declaration

    Swift

    public final var hex: UInt32 { get }

    Return Value

    A UInt32 that represents the hexadecimal color.

  • Returns the RGBA (red, green, blue, alpha) components, specified as values from 0.0 to 1.0.

    Declaration

    Swift

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

    Return Value

    The RGBA components as a tuple (r, g, b, a).

  • hsl

    Returns the HSL (hue, saturation, lightness) components, specified as values from 0.0 to 1.0.

    Declaration

    Swift

    public final var hsl: (h: CGFloat, s: CGFloat, l: CGFloat) { get }

    Return Value

    The HSL components as a tuple (h, s, l).

  • hsb

    Returns the HSB (hue, saturation, brightness) components, specified as values from 0.0 to 1.0.

    Declaration

    Swift

    public final var hsb: (h: CGFloat, s: CGFloat, b: CGFloat) { get }

    Return Value

    The HSB components as a tuple (h, s, b).

  • Returns the CMYK (cyan, magenta, yellow, key) components, specified as values from 0.0 to 1.0.

    Declaration

    Swift

    public final var cmyk: (c: CGFloat, m: CGFloat, y: CGFloat, k: CGFloat) { get }

    Return Value

    The CMYK components as a tuple (c, m, y, k).

  • Returns an alpha-adjusted UIColor.

    Declaration

    Swift

    public final func alpha(_ alpha: CGFloat) -> UIColor

    Return Value

    A UIColor with an adjust alpha component (shorthand for colorWithAlphaComponent).

  • Returns a UIColor from the given hexidecimal integer.

    Declaration

    Swift

    public static func hex(_ hex: UInt32, alpha: CGFloat = 1) -> UIColor

    Parameters

    hex

    The color value.

    alpha

    The alpha component.

    Return Value

    A UIColor initialized with the given hex value.

  • Returns a UIColor from the given RGB components.

    Declaration

    Swift

    public static func rgb(_ red: UInt8, _ green: UInt8, _ blue: UInt8, alpha: CGFloat = 1) -> UIColor

    Parameters

    red

    The red component in range of 0-255.

    green

    The green component in range of 0-255.

    blue

    The blue component in range of 0-255.

    alpha

    The alpha component.

    Return Value

    A UIColor initialized with the given RGB components.

  • Model is an enum for describing and converting color models.

    • rgb: Red, Green, Blue color representation
    • hsl: Hue, Saturation, Lightness color representation
    • hsb: Hue, Saturation, Brightness color representation
    • cmyk: Cyan, Magenta, Yellow, Key (Black) color representation
    • hex: UInt32 (hex) color representation
    See more

    Declaration

    Swift

    public enum Model