Color
public extension Color
-
SwifterSwift: Random color.
Declaration
Swift
static var random: Color { get }
-
SwifterSwift: RGB components for a Color (between 0 and 255).
UIColor.red.rgbComponents.red -> 255 NSColor.green.rgbComponents.green -> 255 UIColor.blue.rgbComponents.blue -> 255
Declaration
Swift
var rgbComponents: (red: Int, green: Int, blue: Int) { get }
-
SwifterSwift: RGB components for a Color represented as CGFloat numbers (between 0 and 1)
UIColor.red.rgbComponents.red -> 1.0 NSColor.green.rgbComponents.green -> 1.0 UIColor.blue.rgbComponents.blue -> 1.0
Declaration
Swift
var cgFloatComponents: (red: CGFloat, green: CGFloat, blue: CGFloat) { get }
-
SwifterSwift: Get components of hue, saturation, and brightness, and alpha (read-only).
Declaration
Swift
var hsbaComponents: (hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat) { get }
-
SwifterSwift: Hexadecimal value string (read-only).
Declaration
Swift
var hexString: String { get }
-
SwifterSwift: Short hexadecimal value string (read-only, if applicable).
Declaration
Swift
var shortHexString: String? { get }
-
SwifterSwift: Short hexadecimal value string, or full hexadecimal string if not possible (read-only).
Declaration
Swift
var shortHexOrHexString: String { get }
-
SwifterSwift: Alpha of Color (read-only).
Declaration
Swift
var alpha: CGFloat { get }
-
SwifterSwift: CoreImage.CIColor (read-only)
Declaration
Swift
var coreImageColor: CoreImage.CIColor? { get }
-
SwifterSwift: Get UInt representation of a Color (read-only).
Declaration
Swift
var uInt: UInt { get }
-
SwifterSwift: Get color complementary (read-only, if applicable).
Declaration
Swift
var complementary: Color? { get }
-
SwifterSwift: Blend two Colors
Declaration
Parameters
color1
first color to blend
intensity1
intensity of first color (default is 0.5)
color2
second color to blend
intensity2
intensity of second color (default is 0.5)
Return Value
Color created by blending first and seond colors.
-
SwifterSwift: Lighten a color
let color = Color(red: r, green: g, blue: b, alpha: a) let lighterColor: Color = color.lighten(by: 0.2)
Declaration
Swift
func lighten(by percentage: CGFloat = 0.2) -> Color
Parameters
percentage
Percentage by which to lighten the color
Return Value
A lightened color
-
SwifterSwift: Darken a color
let color = Color(red: r, green: g, blue: b, alpha: a) let darkerColor: Color = color.darken(by: 0.2)
Declaration
Swift
func darken(by percentage: CGFloat = 0.2) -> Color
Parameters
percentage
Percentage by which to darken the color
Return Value
A darkened color
-
SwifterSwift: Create Color from RGB values with optional transparency.
Declaration
Swift
convenience init?(red: Int, green: Int, blue: Int, transparency: CGFloat = 1)
Parameters
red
red component.
green
green component.
blue
blue component.
transparency
optional transparency value (default is 1).
-
SwifterSwift: Create Color from hexadecimal value with optional transparency.
Declaration
Swift
convenience init?(hex: Int, transparency: CGFloat = 1)
Parameters
hex
hex Int (example: 0xDECEB5).
transparency
optional transparency value (default is 1).
-
SwifterSwift: Create Color from hexadecimal string with optional transparency (if applicable).
Declaration
Swift
convenience init?(hexString: String, transparency: CGFloat = 1)
Parameters
hexString
hexadecimal string (examples: EDE7F6, 0xEDE7F6, #EDE7F6, #0ff, 0xF0F, ..).
transparency
optional transparency value (default is 1).
-
SwifterSwift: Create Color from a complementary of a Color (if applicable).
Declaration
Swift
convenience init?(complementaryFor color: Color)
Parameters
color
color of which opposite color is desired.
-
SwifterSwift: Brand identity color of popular social media platform.
See moreDeclaration
Swift
struct Social
-
SwifterSwift: Google Material design colors palette.
See moreDeclaration
Swift
struct Material