UIColor
extension UIColor
-
Returns a UIColor from the given hexidecimal integer.
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).
Return Value
A UIColor initialized with the given color value.
-
Returns a UIColor from a hue-saturation-lightness (HSL) set.
Declaration
Swift
public convenience init(hue: CGFloat, saturation: CGFloat, lightness: CGFloat, alpha: CGFloat = 1)Parameters
hueThe hue component of the color object, specified as a value from 0.0 to 1.0.
saturationThe saturation component of the color object, specified as a value from 0.0 to 1.0.
lightnessThe lightness component of the color object, specified as a value from 0.0 to 1.0.
alphaThe opacity component of the color object, specified as a value from 0.0 to 1.0 (optional).
Return Value
A UIColor initialized with the given color value.
-
Returns a UIColor from a cyan-magenta-yellow-key (CMYK) set.
Declaration
Swift
public convenience init(cyan: CGFloat, magenta: CGFloat, yellow: CGFloat, key: CGFloat, alpha: CGFloat = 1)Parameters
cyanThe cyan component of the color object, specified as a value from 0.0 to 1.0.
magentaThe magenta component of the color object, specified as a value from 0.0 to 1.0.
yellowThe yellow component of the color object, specified as a value from 0.0 to 1.0.
keyThe key (black) component of the color object, specified as a value from 0.0 to 1.0.
alphaThe opacity component of the color object, specified as a value from 0.0 to 1.0 (optional).
Return Value
A UIColor initialized with the given color value.
-
Returns a UIColor from a given hex color string.
Declaration
Swift
public convenience init(hexString: String, alpha: CGFloat = 1)Parameters
hexStringThe hex color string, e.g.:
#9443FB
or9443FB
.Return Value
A UIColor initialized with the color specified by the hexString.
-
Returns a UIColor initialized with color components divided by 255.0.
Declaration
Swift
public convenience init(red: UInt8, green: UInt8, blue: UInt8)Parameters
redInteger representation of the red component in range of 0-255.
greenInteger representation of the green component in range of 0-255.
blueInteger representation of the blue component in range of 0-255.
-
Returns a random UIColor with hue, saturation, and brightness ranging from 0.5 to 1.0.
Declaration
Swift
public static var random: UIColor { get } -
Lightens the given color by the given percentage.
Declaration
Swift
public final func lightened(by amount: CGFloat) -> UIColorParameters
amountThe percentage by which to lighten the color. Valid values are from
0.0to1.0, or for a more readable format0%to100%.Return Value
The lightened color.
-
Darkens the given color by the given percentage.
Declaration
Swift
public final func darkened(by amount: CGFloat) -> UIColorParameters
amountThe percentage by which to darken the color. Valid values are from
0.0to1.0, or for a more readable format0%to100%.Return Value
The darkened color.
-
Returns the color represenation as a hexadecimal string, prefixed with ‘#’.
Declaration
Swift
public final var hexString: String { get }Return Value
The hexadecimal string representation of the color.
-
Returns the color representation as a 32-bit integer.
Declaration
Swift
public final var hex: UInt32 { get }Return Value
A UInt32 that represents the hexadecimal color.
-
Returns the RGBA (red, green, blue, alpha) components, specified as values from 0.0 to 1.0.
Declaration
Swift
public final var rgba: (r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat) { get }Return Value
The RGBA components as a tuple (r, g, b, a).
-
Returns the HSL (hue, saturation, lightness) components, specified as values from 0.0 to 1.0.
Declaration
Swift
public final var hsl: (h: CGFloat, s: CGFloat, l: CGFloat) { get }Return Value
The HSL components as a tuple (h, s, l).
-
Returns the HSB (hue, saturation, brightness) components, specified as values from 0.0 to 1.0.
Declaration
Swift
public final var hsb: (h: CGFloat, s: CGFloat, b: CGFloat) { get }Return Value
The HSB components as a tuple (h, s, b).
-
Returns the CMYK (cyan, magenta, yellow, key) components, specified as values from 0.0 to 1.0.
Declaration
Swift
public final var cmyk: (c: CGFloat, m: CGFloat, y: CGFloat, k: CGFloat) { get }Return Value
The CMYK components as a tuple (c, m, y, k).
-
Returns an alpha-adjusted UIColor.
Declaration
Swift
public final func alpha(_ alpha: CGFloat) -> UIColorReturn Value
A UIColor with an adjust alpha component (shorthand for
colorWithAlphaComponent). -
Returns a UIColor from the given hexidecimal integer.
Declaration
Swift
public static func hex(_ hex: UInt32, alpha: CGFloat = 1) -> UIColorParameters
hexThe color value.
alphaThe alpha component.
Return Value
A UIColor initialized with the given hex value.
-
Returns a UIColor from the given RGB components.
Declaration
Swift
public static func rgb(_ red: UInt8, _ green: UInt8, _ blue: UInt8, alpha: CGFloat = 1) -> UIColorParameters
redThe red component in range of 0-255.
greenThe green component in range of 0-255.
blueThe blue component in range of 0-255.
alphaThe alpha component.
Return Value
A UIColor initialized with the given RGB components.
-
Model is an enum for describing and converting color models.
rgb: Red, Green, Blue color representationhsl: Hue, Saturation, Lightness color representationhsb: Hue, Saturation, Brightness color representationcmyk: Cyan, Magenta, Yellow, Key (Black) color representationhex: UInt32 (hex) color representation
Declaration
Swift
public enum Model
View on GitHub
Install in Dash
UIColor Extension Reference