Color
public typealias Color = UIKit.UIColor
-
Mechanica
Returns the hexadecimal string representation of
selfin the sRGB space.Example:
Color.red.hexString ->"#FF0000" Color.black.hexString -> "#000000" Color.gray.hexString -> "#7F7F7F" Color.green.hexString -> "#00FF00"Declaration
Swift
public final var hexString: String? { get } -
Mechanica
Initializes and returns a random color object in the sRGB space.
Declaration
Swift
public class func random(randomAlpha: Bool = false) -> Self
-
Mechanica
Alias for RGBA color space components
Declaration
Swift
public typealias RGBA = (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) -
Mechanica
Returns the color’s RGBA components as Ints.
Declaration
Swift
public final var rgbaComponents: (red: Int, green: Int, blue: Int, alpha: Int)? { get } -
Mechanica
Returns the color’s RGBA components as a tuple of
CGFloat.Declaration
Swift
public final var rgba: RGBA? { get } -
Mechanica
Creates a
newcolor in the sRGB color space (if needed) guard letthat matches (or closely approximates) the current color. Although the new color might have different component values, it looks the same as the original.Note
WWDC 2016 - 712Declaration
Swift
public final func convertedToCompatibleSRGBColor() -> Color?
-
Mechanica
Returns a sRGB color from a hexadecimal integer.
Example:
Color(hex: 0xFF0000) Color(hex: 0xFF0000, alpha: 0.5)Declaration
Swift
public convenience init(hex: UInt32, alpha: CGFloat = 1)Parameters
hexThe hex component of the color object, specified as a value from 0x000000 to 0xFFFFFF
alphaThe opacity component of the color object, specified as a value from 0.0 to 1.0 (optional).
-
Mechanica
Creates and returns an Color object given an hex color string.
Note
Supported formats:
RGB,#RGB,RGBA,#RGBA,RRGGBB,#RRGGBB,RRGGBBAA,#RRGGBBAA).Declaration
Swift
public convenience init?(hexString: String)Parameters
hexStringThe hex color string (e.g.:
#551a8b,551a8b,551A8B,#FFF).
-
Mechanica
Alias for HSBA color space components
Declaration
Swift
public typealias HSBA = (hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat) -
Mechanica
Returns the components that make up the color in the HSBA color space.
Declaration
Swift
public final var hsba: HSBA? { get }
-
Mechanica
Blends two colors together.
Note
The sum of the two percentages must be 1.0 otherwise the blendind operation is not executed.Declaration
Parameters
firstColorFirst color to blend.
firstPercentageIntensity of first color (default is 0.5)
secondColorSecond color to blend.
secondPercentageIntensity of second color (default is 0.5)
Return Value
a
new colorblending the two colors.
Color Extension Reference