UIColor
Undocumented
-
Initializes and returns a color object using RGB component values as Int and an optional opacity value. - parameter red: The red value of the color object. Red values below 0 are interpreted as 0, and values above 255 are interpreted as 255. - parameter green: The green value of the color object. Green values below 0 are interpreted as 0, and values above 255 are interpreted as 255. - parameter blue: The blue value of the color object. Blue values below 0 are interpreted as 0, and values above 255 are interpreted as 255. - parameter transparency: Optional opacity value of the color object, specified as a value from 0.0 to 1.0. Alpha values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0. It defaults to 1.0. - returns: The color object. - seealso:
init(red:green:blue:alpha)Declaration
Swift
public convenience init(red: Int, green: Int, blue: Int, transparency: CGFloat = 1.0)Parameters
redThe red value of the color object. Red values below 0 are interpreted as 0, and values above 255 are interpreted as 255.
greenThe green value of the color object. Green values below 0 are interpreted as 0, and values above 255 are interpreted as 255.
blueThe blue value of the color object. Blue values below 0 are interpreted as 0, and values above 255 are interpreted as 255.
transparencyOptional opacity value of the color object, specified as a value from 0.0 to 1.0. Alpha values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0. It defaults to 1.0.
Return Value
The color object.
-
Initializes and returns a color object using RGB component values as a hexadecimal Int and an optional opacity value. - parameter hex: Hexadecimal value for RGB (example: 0xFF0000). - parameter alpha: Optional opacity value of the color object, specified as a value from 0.0 to 1.0. Alpha values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0. It defaults to 1.0. - returns: The color object. - seealso:
init?(hexString:alpha:)Declaration
Swift
public convenience init(hex: Int, alpha: CGFloat = 1.0)Parameters
hexHexadecimal value for RGB (example: ).
alphaOptional opacity value of the color object, specified as a value from 0.0 to 1.0. Alpha values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0. It defaults to 1.0.
Return Value
The color object.
-
Initializes and returns an optional color object using RGB component values as a hexadecimal String and an optional opacity value.
It uses
Scanner‘sscanHexInt32. If the scanning fails it returns anil. - parameter hexString: Hexadecimal value for RGB (example:FF0000
or#FF0000
) - parameter alpha: Optional opacity value of the color object, specified as a value from 0.0 to 1.0. Alpha values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0. It defaults to 1.0. - returns: The optional color object. - seealso:init(hex:alpha:)Declaration
Swift
public convenience init?(hexString: String, alpha: CGFloat = 1.0)Parameters
hexStringHexadecimal value for RGB (example: or )
alphaOptional opacity value of the color object, specified as a value from 0.0 to 1.0. Alpha values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0. It defaults to 1.0.
Return Value
The optional color object.
-
The red component of color’s RGBA representation. - seealso:
greenComponent- seealso:blueComponent- seealso:alphaComponentDeclaration
Swift
public var redComponent: Int -
The green component of color’s RGBA representation. - seealso:
redComponent- seealso:blueComponent- seealso:alphaComponentDeclaration
Swift
public var greenComponent: Int -
The blue component of color’s RGBA representation. - seealso:
redComponent- seealso:greenComponent- seealso:alphaComponentDeclaration
Swift
public var blueComponent: Int -
The alpha channel of color’s RGBA representation. - seealso:
redComponent- seealso:greenComponent- seealso:blueComponentDeclaration
Swift
public var alphaComponent: CGFloat
-
Creates a darker color from the receiver by altering it’s brightness by a percent (using the HSBA color space). - parameter percent: The percentage for decreasing brightness. Values below 0 are interpreted as 0, and values above 100 are interpreted as 100. - returns: The darker color object. - seealso:
lighten(_:)- seealso:lighter(than:)- seealso:darker(than:)Declaration
Swift
public func darken(_ percent: Int) -> UIColorParameters
percentThe percentage for decreasing brightness. Values below 0 are interpreted as 0, and values above 100 are interpreted as 100.
Return Value
The darker color object.
-
Creates a lighter color from the receiver by altering it’s brightness by a percent (using the HSBA color space). - parameter percent: The percentage for increasing brightness. Values below 0 are interpreted as 0, and values above 100 are interpreted as 100. - returns: The lighter color object. - seealso:
darken(_:)- seealso:lighter(than:)- seealso:darker(than:)Declaration
Swift
public func lighten(_ percent: Int) -> UIColorParameters
percentThe percentage for increasing brightness. Values below 0 are interpreted as 0, and values above 100 are interpreted as 100.
Return Value
The lighter color object.
-
Returns a Boolean value that indicates whether a given color is lighter than the receiver (compering their brightness values - from HSBA color space) - parameter other: the other color to compare to - returns:
trueif other is lighter, otherwisefalse- seealso:darker(than:)- seealso:darken(_:)- seealso:lighten(_:)Declaration
Swift
public func lighter(than other: UIColor) -> BoolParameters
otherthe other color to compare to
Return Value
trueif other is lighter, otherwisefalse -
Returns a Boolean value that indicates whether a given color is darker than the receiver (compering their brightness values - from HSBA color space) - parameter other: the other color to compare to - returns:
trueif other is darker, otherwisefalse- seealso:lighter(than:)- seealso:darken(_:)- seealso:lighten(_:)Declaration
Swift
public func darker(than other: UIColor) -> BoolParameters
otherthe other color to compare to
Return Value
trueif other is darker, otherwisefalse
View on GitHub
UIColor Extension Reference