UIColor

public extension UIColor

Alderis provides extensions to UIColor for the purpose of serializing and deserializing colors into representations that can be stored in property lists, JSON, and similar formats.

  • Initializes and returns a color object using data from the specified object.

    The value is expected to be one of:

    • An array of 3 or 4 integer RGB or RGBA color components, with values between 0 and 255 (e.g. [218, 192, 222])
    • A CSS-style hex string, with an optional alpha component (e.g. #DAC0DE or #DACODE55)
    • A short CSS-style hex string, with an optional alpha component (e.g. #DC0 or #DC05)

    Use -[UIColor initWithHbcp_propertyListValue:] to access this method from Objective-C.

    Declaration

    Swift

    @nonobjc
    convenience init?(propertyListValue: ColorPropertyListValue?)

    Parameters

    value

    The object to retrieve data from. See the discussion for the supported object types.

    Return Value

    An initialized color object, or nil if the value does not conform to the expected type. The color information represented by this object is in the device RGB colorspace.

  • Maps init(propertyListValue:) to Objective-C due to Swift limitations. This is an implementation detail. Ignore this and use UIColor(propertyListValue:) or -[UIColor initWithHbcp_propertyListValue:] as per usual.

    Declaration

    Swift

    @objc(initWithHbcp_propertyListValue:)
    convenience init?(_propertyListValueObjC propertyListValue: Any?)

    Parameters

    value

    The object to retrieve data from. See the discussion for the supported object types.

    Return Value

    An initialized color object, or nil if the value does not conform to the expected type. The color information represented by this object is in the device RGB colorspace. device RGB colorspace.

  • Returns a string that represents the color.

    The output is a string in the format #AABBCC:0.5, where the initial #AABBCC portion is a 6-character CSS-style hex string, and the final :0.5 portion represents the alpha value. If the color’s alpha value is 1, the alpha portion is excluded.

    If the color is dynamic, for instance if it is a UIKit system color, or initialised via UIColor(dynamicProvider:), the color that matches the current trait collection is used.

    Declaration

    Swift

    @objc(hbcp_propertyListValue)
    var propertyListValue: String { get }

    Return Value

    A string representing the color, in the format discussed above.

  • Returns a hexadecimal string that represents the color.

    The output is a string in the format #AABBCCDD, where the initial #AABBCC portion is a 6-character CSS-style hex string, and the final DD portion is the hexadecimal representation of the alpha value, supported by recent web browsers.

    If the color is dynamic, for instance if it is a UIKit system color, or initialised via UIColor(dynamicProvider:), the color that matches the current trait collection is used.

    Declaration

    Swift

    @objc(hbcp_hexString)
    var hexString: String { get }

    Return Value

    A string representing the color, in the format discussed above.

  • Returns an RGB string that represents the color.

    The output is a string in the format of rgba(170, 187, 204, 0.5), or rgb(170, 187, 204) if the color’s alpha value is 1.

    If the color is dynamic, for instance if it is a UIKit system color, or initialised via UIColor(dynamicProvider:), the color that matches the current trait collection is used.

    Declaration

    Swift

    @objc(hbcp_rgbString)
    var rgbString: String { get }

    Return Value

    A string representing the color, in the format discussed above.

  • Returns an HSL string that represents the color.

    The output is a string in the format of hsla(170, 187, 204, 0.5), or hsl(170, 187, 204) if the color’s alpha value is 1.

    If the color is dynamic, for instance if it is a UIKit system color, or initialised via UIColor(dynamicProvider:), the color that matches the current trait collection is used.

    Declaration

    Swift

    @objc(hbcp_hslString)
    var hslString: String { get }

    Return Value

    A string representing the color, in the format discussed above.

  • Returns an Objective-C UIColor string that represents the color.

    The output is a string in the format of [UIColor colorWithRed:0.667 green:0.733 blue:0.800 alpha:1.00].

    If the color is dynamic, for instance if it is a UIKit system color, or initialised via UIColor(dynamicProvider:), the color that matches the current trait collection is used.

    Declaration

    Swift

    @objc(hbcp_objcString)
    var objcString: String { get }

    Return Value

    A string representing the color, in the format discussed above.

  • Returns a Swift UIColor string that represents the color.

    The output is a string in the format of UIColor(red: 0.667, green: 0.733, blue: 0.800, alpha: 1.00).

    If the color is dynamic, for instance if it is a UIKit system color, or initialised via UIColor(dynamicProvider:), the color that matches the current trait collection is used.

    Declaration

    Swift

    @objc(hbcp_swiftString)
    var swiftString: String { get }

    Return Value

    A string representing the color, in the format discussed above.