UIColor

extension UIColor
  • Initialize a color using a string containing hex values.

    Declaration

    Swift

    public convenience init(hex: String, alpha: CGFloat = 1.0)

    Parameters

    hex

    string of 6 hexadecimal digits 0-9 and A-F. May start with a ‘#’ which will be ignored.

    alpha

    optional alpha component for the color. By default it is 1.0 (opaque)

  • Make a color that is lighter than the current one by adjusting the ‘brightness’ component in HSB space.

    Declaration

    Swift

    public func lighter(_ factor: CGFloat = 0.25) -> UIColor

    Parameters

    factor

    how much to increase current brightness. A value of 0.5 will increase the existing value by 50%.

    Return Value

    new UIColor

  • Make a color that is darker than the current one by adjust the ‘brightness’ component in HSB space.

    Declaration

    Swift

    public func darker(_ factor: CGFloat = 0.25) -> UIColor

    Parameters

    factor

    how much to decrease current brightness. A value of 0.25 will decrease existing value by 25%.

    Return Value

    new UIColor