Colorable
public protocol Colorable : RawRepresentable where Self.RawValue == String
Any named color asset that can be loaded from an asset catalog (primarily for use with string-based enums).
All properties and functions have default implementations. At a minimum just have your string-based enum conform
to Colorable
(and have an asset catalog with matching assets). If your enum and assets live inside a Swift
package, override bundle
to return .module
. If your assets are categorized within their asset catalog by
a namespace, then override namespace
to return the proper string prefix.
-
bundle
Default implementationThe bundle containing the color assets for this enum (default is
.main
)Default Implementation
The bundle containing the color assets for this enum (default is
.main
)Declaration
Swift
static var bundle: Bundle { get }
-
namespace
Default implementationOptional namespace for the color assets (default is
nil
)Default Implementation
Optional namespace for the color assets (default is
nil
)Declaration
Swift
static var namespace: String? { get }
-
fallbackColor
Default implementationFallback color to use in case a color asset cannot be loaded (default is
.systemPink
)Default Implementation
Fallback color to use in case a color asset cannot be loaded (default is
.systemPink
)Declaration
Swift
static var fallbackColor: UIColor { get }
-
loadColor()
Default implementationLoads the named color.
Default implementation uses
UIColor(named:in:compatibleWith:)
passing in the associatednamespace
(prepended torawValue
) andbundle
.Default Implementation
Loads the named color.
Default implementation uses
UIColor(named:in:compatibleWith:)
passing in the associatednamespace
(prepended torawValue
) andbundle
.Declaration
Swift
func loadColor() -> UIColor?
Return Value
The named color or else
nil
if the named asset cannot be loaded -
color
Default implementationA color asset for this name value.
Default implementation calls
loadColor
and nil-coalesces tofallbackColor
.Default Implementation
A color asset for this name value.
Default implementation calls
loadColor
and nil-coalesces tofallbackColor
.Declaration
Swift
var color: UIColor { get }