UIColor

  • Available for watchOS.

    Get the color associated with the given coding key.

    1. This will first check to see if the string is a HEX-coded string and initialize the string using the UIColor.init?(hexString:) initializer.

    2. If this is not a hex color, then the asset catalog for the main bundle will be checked using the UIColor.init?(named:) initializer.

    3. Finally, the method will look for a file imbedded in the given bundle named ColorInfo.plist. This allows the app to define a mapping of colors in a single place using a plist with key/value pairs. The mapping is expected to include key/value pairs where the value is a hex-coded string. The plist method is slower (because the file must be openned and inspected) so it is only recommended for applications that need to support iOS 10.

  • Available for iOS and tvOS.

    Get the color associated with the given coding key.

    1. This will first check to see if the string is a HEX-coded string and initialize the string using the UIColor.init?(hexString:) initializer.

    2. If this is not a hex color, then the asset catalog for the given bundle will be checked using the UIColor.init?(named:, in:, compatibleWith:) initializer.

    3. Finally, the method will look for a file imbedded in the given bundle named ColorInfo.plist. This allows the app to define a mapping of colors in a single place using a plist with key/value pairs. The mapping is expected to include key/value pairs where the value is a hex-coded string. The plist method is slower (because the file must be openned and inspected) so it is only recommended for applications that need to support iOS 10.

    Declaration

    Swift

    open class func rsd_color(named name: String, in bundle: Bundle?, compatibleWith traitCollection: UITraitCollection?) -> UIColor?

    Parameters

    name

    The name of the color. Either a HEX-code or a custom-defined key.

    bundle

    The bundle with either the Color asset (iOS/tvOS 11) or the ColorInfo.plist file (all versions).

    traitCollection

    The trait collection to use (if supported).

    Return Value

    The color created.

  • Initialize a UIColor with a hex string.

    Declaration

    Swift

    public convenience init?(hexString: String)

    Parameters

    hexString

    An RGB color defined using a hex code.

    Return Value

    A color if the hex is valid.