UIColor

extension UIColor
  • Initializes a UIColor with RGB values and optional alpha.

    Declaration

    Swift

    public convenience init(
        red redInput: Int,
        green greenInput: Int,
        blue blueInput: Int,
        alpha alphaInput: CGFloat = 1
    )

    Parameters

    redInput

    Required. The amount of red; from 0 to 255

    greenInput

    Required. The amount of green; from 0 to 255

    blueInput

    Required. The amount of blue; from 0 to 255

    alphaInput

    Optional. The alpha value; from 0 to 1; default is 1.

HEX

  • Initialize values of UIColor from hexadecimal numbers (e.g. 0xED2C61).

    • Three-digit numbers (e.g. 0xFFF) aren’t supported in this version. Use init(hexString:).

    Declaration

    Swift

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

    Parameters

    hex

    Hexadecimal color number (from 0x000000 to 0xFFFFFF)

    alpha

    Alpha value for the color; default is 1.0

  • Initializes a UIColor from a hexadecimal color code.

    • The following formats are supported: ed2c61, #aeaeae, eee, and #123.

    Declaration

    Swift

    public convenience init?(hexString hexStringInput: String)

    Parameters

    hexStringInput

    Required. The string which contains a hexadecimal color code.