-
Declaration
Swift
public var redComponent: Double
-
Declaration
Swift
public var greenComponent: Double
-
Declaration
Swift
public var blueComponent: Double
-
Declaration
Swift
public var alphaComponent: Double
-
Declaration
Swift
public init(red: Double, green: Double, blue: Double, alpha: Double)
-
Declaration
Swift
public static let red: Color
-
Declaration
Swift
public static let green: Color
-
Declaration
Swift
public static let blue: Color
-
Declaration
Swift
public static let black: Color
-
Declaration
Swift
public static let white: Color
-
The maximum representable integer for each color component.
Declaration
Swift
private static let maxHex: Int
-
Initializes a new
Color
instance of given hexadecimal color string.Given string will be stripped from a single leading “#”, if applicable. Resulting string must met any of the following criteria:
- Is a string with 8-characters and therefore a fully fledged hexadecimal
color representation including an alpha component. Given value will remain
untouched before conversion. Example:
ffeebbaa
- Is a string with 6-characters and therefore a fully fledged hexadecimal color
representation excluding an alpha component. Given RGB color components will
remain untouched and an alpha component of
0xff
(opaque) will be extended before conversion. Example:ffeebb
->ffeebbff
- Is a string with 4-characters and therefore a shortened hexadecimal color
representation including an alpha component. Each single character will be
doubled before conversion. Example:
feba
->ffeebbaa
Is a string with 3-characters and therefore a shortened hexadecimal color representation excluding an alpha component. Given RGB color character will be doubled and an alpha of component of
0xff
(opaque) will be extended before conversion. Example:feb
->ffeebbff
Throws
.invalidColor
if given string does not match any of the above mentioned criteria or is not a valid hex color.Declaration
Swift
public init(hex string: String, leadingAlpha: Bool = false) throws
Parameters
string
The hexadecimal color string.
leadingAlpha
Indicate whether given string should be treated as ARGB (
true
) or RGBA (false
) - Is a string with 8-characters and therefore a fully fledged hexadecimal
color representation including an alpha component. Given value will remain
untouched before conversion. Example:
-
Initializes a new
Color
instance of given hexadecimal color values.Declaration
Swift
public init(hex color: Int, leadingAlpha: Bool = false)
Parameters
color
The hexadecimal color value, incl. red, green, blue and alpha
leadingAlpha
Indicate whether given code should be treated as ARGB (
true
) or RGBA (false
)
-
Sanitizes given hexadecimal color string (strips # and forms proper length).
Throws
.invalidColor
if given string is not of proper lengthDeclaration
Swift
private static func sanitize(hex string: String, leadingAlpha: Bool) throws -> String
Parameters
string
The hexadecimal color string to sanitize
leadingAlpha
Indicate whether given and returning string should be treated as ARGB (
true
) or RGBA (false
)Return Value
The sanitized hexadecimal color string