Color
public typealias Color = UIKit.UIColor
-
Mechanica
Returns the hexadecimal string representation of
self
in the sRGB space.Declaration
Swift
public final var hexString: String
-
Mechanica
Initializes and returns a random color object in the sRGB space.
Declaration
Swift
public class func random() -> Self
-
Mechanica
Returns the color’s RGBA components as Ints.
Declaration
Swift
public final var rgbaInt: (red: Int, green: Int, blue: Int, alpha: Int)?
-
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 CGFloats.
Declaration
Swift
public final var rgba: RGBA?
-
Mechanica
Creates a
new
color in the sRGB color space that 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 convertingToCompatibleSRGBColor() -> Color?
-
Mechanica
Mixes the given color object with the receiver. Specifically, takes the average of each of the RGB components, optionally weighted by the given percentage.
Note
See lighter and darker colorDeclaration
Swift
public final func mixing(with color: Color, by percentage: CGFloat = 0.5) -> Color?
Parameters
color
color to be mixed.
percentage
mixing weight. (by default (0.5) takes the average of each of the RGBA components.
Return Value
a
new color
mixingself
with the givencolor
. -
Mechanica
Returns a
new
color derived fromself
darkened by the given percentage in the RGBA color space.Note
Thenew
color is obtained mixingself
with the black color.Declaration
Swift
public final func darkened(by percentage: CGFloat = 0.25) -> Color?
-
Mechanica
Returns a
new
color derived fromself
lightened by the given percentage in the RGBA color space.Note
Thenew
color is obtained mixingself
with the white color.Declaration
Swift
public final func lightened(by percentage: CGFloat = 0.25) -> Color?
-
Mechanica
Returns a sRGB color from a hexadecimal integer.
Color(hex: 0xFF0000) Color(hex: 0xFF0000, alpha: 0.5)
Declaration
Swift
public convenience init(hex: UInt32, alpha: CGFloat = 1)
Parameters
hex
The hex component of the color object, specified as a value from 0x000000 to 0xFFFFFF
alpha
The 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
hexString
The hex color string (e.g.:
#551a8b
,551a8b
,551A8B
,#FFF
).
-
Mechanica
Returns the components that make up the color in the HSBA color space.
Declaration
Swift
public final var hsba: HSBA?
-
Mechanica
Alias for HSBA color space components
Declaration
Swift
public typealias HSBA = (hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat)
-
Mechanica
Returns a
new
color derived fromself
lightened increasing the brightness by apercentage
in the HSB color space.Declaration
Swift
public final func lightened(byIncreasingBrightness percentage: CGFloat = 0.25) -> Color?
-
Mechanica
Returns a
new
color derived fromself
darkened decreasing the brightness by apercentage
in the HSB color space.Declaration
Swift
public final func darkened(byDecreasingBrightness percentage: CGFloat = 0.25) -> Color?
-
Mechanica
Returns a
new
color derived fromself
saturating the hue (increasing the saturation) by apercentage
in the HSB color space, making it more intense and darker.Note
Increasing the saturation makes the color less closer to white.Declaration
Swift
public final func shaded(byIncreasingSaturation percentage: CGFloat = 0.25) -> Color?
-
Mechanica
Returns a
new
color derived fromself
desaturating the hue (decreasing the saturation) by apercentage
in the HSB color space, making it less intense.Note
Decreasing the saturation makes the color closer to white.Declaration
Swift
public final func tinted(byDecreasingSaturation percentage: CGFloat = 0.25) -> Color?
-
Declaration
Swift
public enum Flat