UIColor
-
Available for watchOS.
Get the color associated with the given coding key.
This will first check to see if the string is a HEX-coded string and initialize the string using the
UIColor.init?(hexString:)initializer.If this is not a hex color, then the asset catalog for the main bundle will be checked using the
UIColor.init?(named:)initializer.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.
This will first check to see if the string is a HEX-coded string and initialize the string using the
UIColor.init?(hexString:)initializer.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.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
nameThe name of the color. Either a HEX-code or a custom-defined key.
bundleThe bundle with either the Color asset (iOS/tvOS 11) or the
ColorInfo.plist
file (all versions).traitCollectionThe trait collection to use (if supported).
Return Value
The color created.
-
Initialize a
UIColorwith a hex string.Declaration
Swift
public convenience init?(hexString: String)Parameters
hexStringAn RGB color defined using a hex code.
Return Value
A color if the hex is valid.
View on GitHub
UIColor Extension Reference