Color
public enum Color : Encodable
extension Color: CustomPlaygroundDisplayConvertible
extension Color: ExpressibleByIntegerLiteral
Data structure that stores color, optionally with opacity.
Color can be expressed in a variety of ways:
As a one of 100+ CSS named colors :
let darkRed = Color.darkRed
As red, green and blue pixel intensities with optional alpha channel for transparency:
let black = Color.RGB(255, 255, 255) let blackTransparent = Color.RGB(255, 255, 255, 0.2)
As hue, saturation and lightness values, also with optional transparency:
let pink = Color.HSL(300, 100, 50) let pinkTransparent = Color.HSL(300, 100, 50, 0.3)
As a hexadecimal integer literal in
0xRRGGBB
format:let black: Color = 0xffffff
Transparency is expressed as alpha
channel between 0
(transparent) and 1
(opaque). Valid lightness and
saturation values are percentages between 0
and 100
. Hue represents a positive angle smaller than 360°
.
There are no checks, clippings or exceptions that enforce these constraints.
See also
Warning
CSS hexadecimal 3-digit #RGB
and 6-digit+transparency #RRGGBBAA
formats are not supported.
For example the following code doesn’t work as expected:
let black: Color = 0xfff // Blue #000fff
let blackTransparent: Color = 0xffffff88 // Yellow #ffff88
It’s not possible to distinguish between these situations in Swift because they are all of the same type - a
hexadecimal 32-bit integer literal. Failures, tough, are usually very visible and produce a significantly
different result. The only correctly working format for literals is #RRGGBB
.
-
Indian red standard CSS color:
#cd5c5c
orrgb(205,92,92)
.Declaration
Swift
public static let indianRed: Color
-
Light coral standard CSS color:
#f08080
orrgb(240,128,128)
.Declaration
Swift
public static let lightCoral: Color
-
Salmon standard CSS color:
#fa8072
orrgb(250,128,114)
.Declaration
Swift
public static let salmon: Color
-
Dark salmon standard CSS color:
#e9967a
orrgb(233,150,122)
.Declaration
Swift
public static let darkSalmon: Color
-
Light salmon standard CSS color:
#ffa07a
orrgb(255,160,122)
.Declaration
Swift
public static let lightSalmon: Color
-
Crimson standard CSS color:
#dc143c
orrgb(220,20,60)
.Declaration
Swift
public static let crimson: Color
-
Red standard CSS color:
#ff0000
orrgb(255,0,0)
.Declaration
Swift
public static let red: Color
-
Fire brick standard CSS color:
#b22222
orrgb(178,34,34)
.Declaration
Swift
public static let fireBrick: Color
-
Dark red standard CSS color:
#8b0000
orrgb(139,0,0)
.Declaration
Swift
public static let darkRed: Color
-
Pink standard CSS color:
#ffc0cb
orrgb(255,192,203)
.Declaration
Swift
public static let pink: Color
-
Light pink standard CSS color:
#ffb6c1
orrgb(255,182,193)
.Declaration
Swift
public static let lightPink: Color
-
Hot pink standard CSS color:
#ff69b4
orrgb(255,105,180)
.Declaration
Swift
public static let hotPink: Color
-
Deep pink standard CSS color:
#ff1493
orrgb(255,20,147)
.Declaration
Swift
public static let deepPink: Color
-
Medium violet red standard CSS color:
#c71585
orrgb(199,21,133)
.Declaration
Swift
public static let mediumVioletRed: Color
-
Pale violet red standard CSS color:
#db7093
orrgb(219,112,147)
.Declaration
Swift
public static let paleVioletRed: Color
-
Coral standard CSS color:
#ff7f50
orrgb(255,127,80)
.Declaration
Swift
public static let coral: Color
-
Tomato standard CSS color:
#ff6347
orrgb(255,99,71)
.Declaration
Swift
public static let tomato: Color
-
Orange red standard CSS color:
#ff4500
orrgb(255,69,0)
.Declaration
Swift
public static let orangeRed: Color
-
Dark orange standard CSS color:
#ff8c00
orrgb(255,140,0)
.Declaration
Swift
public static let darkOrange: Color
-
Orange standard CSS color:
#ffa500
orrgb(255,165,0)
.Declaration
Swift
public static let orange: Color
-
Gold standard CSS color:
#ffd700
orrgb(255,215,0)
.Declaration
Swift
public static let gold: Color
-
Yellow standard CSS color:
#ffff00
orrgb(255,255,0)
.Declaration
Swift
public static let yellow: Color
-
Light yellow standard CSS color:
#ffffe0
orrgb(255,255,224)
.Declaration
Swift
public static let lightYellow: Color
-
Lemon chiffon standard CSS color:
#fffacd
orrgb(255,250,205)
.Declaration
Swift
public static let lemonChiffon: Color
-
Light goldenrod yellow standard CSS color:
#fafad2
orrgb(250,250,210)
.Declaration
Swift
public static let lightGoldenrodYellow: Color
-
Papaya whip standard CSS color:
#ffefd5
orrgb(255,239,213)
.Declaration
Swift
public static let papayaWhip: Color
-
Moccasin standard CSS color:
#ffe4b5
orrgb(255,228,181)
.Declaration
Swift
public static let moccasin: Color
-
Peach puff standard CSS color:
#ffdab9
orrgb(255,218,185)
.Declaration
Swift
public static let peachPuff: Color
-
Pale goldenrod standard CSS color:
#eee8aa
orrgb(238,232,170)
.Declaration
Swift
public static let paleGoldenrod: Color
-
Khaki standard CSS color:
#f0e68c
orrgb(240,230,140)
.Declaration
Swift
public static let khaki: Color
-
Dark khaki standard CSS color:
#bdb76b
orrgb(189,183,107)
.Declaration
Swift
public static let darkKhaki: Color
-
Lavender standard CSS color:
#e6e6fa
orrgb(230,230,250)
.Declaration
Swift
public static let lavender: Color
-
Thistle standard CSS color:
#d8bfd8
orrgb(216,191,216)
.Declaration
Swift
public static let thistle: Color
-
Plum standard CSS color:
#dda0dd
orrgb(221,160,221)
.Declaration
Swift
public static let plum: Color
-
Violet standard CSS color:
#ee82ee
orrgb(238,130,238)
.Declaration
Swift
public static let violet: Color
-
Orchid standard CSS color:
#da70d6
orrgb(218,112,214)
.Declaration
Swift
public static let orchid: Color
-
Fuchsia standard CSS color:
#ff00ff
orrgb(255,0,255)
.Declaration
Swift
public static let fuchsia: Color
-
Magenta standard CSS color:
#ff00ff
orrgb(255,0,255)
.Declaration
Swift
public static let magenta: Color
-
Medium orchid standard CSS color:
#ba55d3
orrgb(186,85,211)
.Declaration
Swift
public static let mediumOrchid: Color
-
Medium purple standard CSS color:
#9370db
orrgb(147,112,219)
.Declaration
Swift
public static let mediumPurple: Color
-
Blue violet standard CSS color:
#8a2be2
orrgb(138,43,226)
.Declaration
Swift
public static let blueViolet: Color
-
Dark violet standard CSS color:
#9400d3
orrgb(148,0,211)
.Declaration
Swift
public static let darkViolet: Color
-
Dark orchid standard CSS color:
#9932cc
orrgb(153,50,204)
.Declaration
Swift
public static let darkOrchid: Color
-
Dark magenta standard CSS color:
#8b008b
orrgb(139,0,139)
.Declaration
Swift
public static let darkMagenta: Color
-
Purple standard CSS color:
#800080
orrgb(128,0,128)
.Declaration
Swift
public static let purple: Color
-
Rebecca purple standard CSS color:
#663399
orrgb(102,51,153)
.Declaration
Swift
public static let rebeccaPurple: Color
-
Indigo standard CSS color:
#4b0082
orrgb(75,0,130)
.Declaration
Swift
public static let indigo: Color
-
Medium slate blue standard CSS color:
#7b68ee
orrgb(123,104,238)
.Declaration
Swift
public static let mediumSlateBlue: Color
-
Slate blue standard CSS color:
#6a5acd
orrgb(106,90,205)
.Declaration
Swift
public static let slateBlue: Color
-
Dark slate blue standard CSS color:
#483d8b
orrgb(72,61,139)
.Declaration
Swift
public static let darkSlateBlue: Color
-
Green yellow standard CSS color:
#adff2f
orrgb(173,255,47)
.Declaration
Swift
public static let greenYellow: Color
-
Chartreuse standard CSS color:
#7fff00
orrgb(127,255,0)
.Declaration
Swift
public static let chartreuse: Color
-
Lawn green standard CSS color:
#7cfc00
orrgb(124,252,0)
.Declaration
Swift
public static let lawnGreen: Color
-
Lime standard CSS color:
#00ff00
orrgb(0,255,0)
.Declaration
Swift
public static let lime: Color
-
Lime green standard CSS color:
#32cd32
orrgb(50,205,50)
.Declaration
Swift
public static let limeGreen: Color
-
Pale green standard CSS color:
#98fb98
orrgb(152,251,152)
.Declaration
Swift
public static let paleGreen: Color
-
Light green standard CSS color:
#90ee90
orrgb(144,238,144)
.Declaration
Swift
public static let lightGreen: Color
-
Medium spring green standard CSS color:
#00fa9a
orrgb(0,250,154)
.Declaration
Swift
public static let mediumSpringGreen: Color
-
Spring green standard CSS color:
#00ff7f
orrgb(0,255,127)
.Declaration
Swift
public static let springGreen: Color
-
Medium sea green standard CSS color:
#3cb371
orrgb(60,179,113)
.Declaration
Swift
public static let mediumSeaGreen: Color
-
Sea green standard CSS color:
#2e8b57
orrgb(46,139,87)
.Declaration
Swift
public static let seaGreen: Color
-
Forest green standard CSS color:
#228b22
orrgb(34,139,34)
.Declaration
Swift
public static let forestGreen: Color
-
Green standard CSS color:
#008000
orrgb(0,128,0)
.Declaration
Swift
public static let green: Color
-
Dark green standard CSS color:
#006400
orrgb(0,100,0)
.Declaration
Swift
public static let darkGreen: Color
-
Yellow green standard CSS color:
#9acd32
orrgb(154,205,50)
.Declaration
Swift
public static let yellowGreen: Color
-
Olive drab standard CSS color:
#6b8e23
orrgb(107,142,35)
.Declaration
Swift
public static let oliveDrab: Color
-
Olive standard CSS color:
#808000
orrgb(128,128,0)
.Declaration
Swift
public static let olive: Color
-
Dark olive green standard CSS color:
#556b2f
orrgb(85,107,47)
.Declaration
Swift
public static let darkOliveGreen: Color
-
Medium aquamarine standard CSS color:
#66cdaa
orrgb(102,205,170)
.Declaration
Swift
public static let mediumAquamarine: Color
-
Dark sea green standard CSS color:
#8fbc8f
orrgb(143,188,143)
.Declaration
Swift
public static let darkSeaGreen: Color
-
Light sea green standard CSS color:
#20b2aa
orrgb(32,178,170)
.Declaration
Swift
public static let lightSeaGreen: Color
-
Dark cyan standard CSS color:
#008b8b
orrgb(0,139,139)
.Declaration
Swift
public static let darkCyan: Color
-
Teal standard CSS color:
#008080
orrgb(0,128,128)
.Declaration
Swift
public static let teal: Color
-
Aqua standard CSS color:
#00ffff
orrgb(0,255,255)
.Declaration
Swift
public static let aqua: Color
-
Cyan standard CSS color:
#00ffff
orrgb(0,255,255)
.Declaration
Swift
public static let cyan: Color
-
Light cyan standard CSS color:
#e0ffff
orrgb(224,255,255)
.Declaration
Swift
public static let lightCyan: Color
-
Pale turquoise standard CSS color:
#afeeee
orrgb(175,238,238)
.Declaration
Swift
public static let paleTurquoise: Color
-
Aquamarine standard CSS color:
#7fffd4
orrgb(127,255,212)
.Declaration
Swift
public static let aquamarine: Color
-
Turquoise standard CSS color:
#40e0d0
orrgb(64,224,208)
.Declaration
Swift
public static let turquoise: Color
-
Medium turquoise standard CSS color:
#48d1cc
orrgb(72,209,204)
.Declaration
Swift
public static let mediumTurquoise: Color
-
Dark turquoise standard CSS color:
#00ced1
orrgb(0,206,209)
.Declaration
Swift
public static let darkTurquoise: Color
-
Cadet blue standard CSS color:
#5f9ea0
orrgb(95,158,160)
.Declaration
Swift
public static let cadetBlue: Color
-
Steel blue standard CSS color:
#4682b4
orrgb(70,130,180)
.Declaration
Swift
public static let steelBlue: Color
-
Light steel blue standard CSS color:
#b0c4de
orrgb(176,196,222)
.Declaration
Swift
public static let lightSteelBlue: Color
-
Powder blue standard CSS color:
#b0e0e6
orrgb(176,224,230)
.Declaration
Swift
public static let powderBlue: Color
-
Light blue standard CSS color:
#add8e6
orrgb(173,216,230)
.Declaration
Swift
public static let lightBlue: Color
-
Sky blue standard CSS color:
#87ceeb
orrgb(135,206,235)
.Declaration
Swift
public static let skyBlue: Color
-
Light sky blue standard CSS color:
#87cefa
orrgb(135,206,250)
.Declaration
Swift
public static let lightSkyBlue: Color
-
Deep sky blue standard CSS color:
#00bfff
orrgb(0,191,255)
.Declaration
Swift
public static let deepSkyBlue: Color
-
Dodger blue standard CSS color:
#1e90ff
orrgb(30,144,255)
.Declaration
Swift
public static let dodgerBlue: Color
-
Cornflower blue standard CSS color:
#6495ed
orrgb(100,149,237)
.Declaration
Swift
public static let cornflowerBlue: Color
-
Royal blue standard CSS color:
#4169e1
orrgb(65,105,225)
.Declaration
Swift
public static let royalBlue: Color
-
Blue standard CSS color:
#0000ff
orrgb(0,0,255)
.Declaration
Swift
public static let blue: Color
-
Medium blue standard CSS color:
#0000cd
orrgb(0,0,205)
.Declaration
Swift
public static let mediumBlue: Color
-
Dark blue standard CSS color:
#00008b
orrgb(0,0,139)
.Declaration
Swift
public static let darkBlue: Color
-
Navy standard CSS color:
#000080
orrgb(0,0,128)
.Declaration
Swift
public static let navy: Color
-
Midnight blue standard CSS color:
#191970
orrgb(25,25,112)
.Declaration
Swift
public static let midnightBlue: Color
-
Cornsilk standard CSS color:
#fff8dc
orrgb(255,248,220)
.Declaration
Swift
public static let cornsilk: Color
-
Blanched almond standard CSS color:
#ffebcd
orrgb(255,235,205)
.Declaration
Swift
public static let blanchedAlmond: Color
-
Bisque standard CSS color:
#ffe4c4
orrgb(255,228,196)
.Declaration
Swift
public static let bisque: Color
-
Navajo white standard CSS color:
#ffdead
orrgb(255,222,173)
.Declaration
Swift
public static let navajoWhite: Color
-
Wheat standard CSS color:
#f5deb3
orrgb(245,222,179)
.Declaration
Swift
public static let wheat: Color
-
Burly wood standard CSS color:
#deb887
orrgb(222,184,135)
.Declaration
Swift
public static let burlyWood: Color
-
Tan standard CSS color:
#d2b48c
orrgb(210,180,140)
.Declaration
Swift
public static let tan: Color
-
Rosy brown standard CSS color:
#bc8f8f
orrgb(188,143,143)
.Declaration
Swift
public static let rosyBrown: Color
-
Sandy brown standard CSS color:
#f4a460
orrgb(244,164,96)
.Declaration
Swift
public static let sandyBrown: Color
-
Goldenrod standard CSS color:
#daa520
orrgb(218,165,32)
.Declaration
Swift
public static let goldenrod: Color
-
Dark goldenrod standard CSS color:
#b8860b
orrgb(184,134,11)
.Declaration
Swift
public static let darkGoldenrod: Color
-
Peru standard CSS color:
#cd853f
orrgb(205,133,63)
.Declaration
Swift
public static let peru: Color
-
Chocolate standard CSS color:
#d2691e
orrgb(210,105,30)
.Declaration
Swift
public static let chocolate: Color
-
Saddle brown standard CSS color:
#8b4513
orrgb(139,69,19)
.Declaration
Swift
public static let saddleBrown: Color
-
Sienna standard CSS color:
#a0522d
orrgb(160,82,45)
.Declaration
Swift
public static let sienna: Color
-
Brown standard CSS color:
#a52a2a
orrgb(165,42,42)
.Declaration
Swift
public static let brown: Color
-
Maroon standard CSS color:
#800000
orrgb(128,0,0)
.Declaration
Swift
public static let maroon: Color
-
White standard CSS color:
#ffffff
orrgb(255,255,255)
.Declaration
Swift
public static let white: Color
-
Snow standard CSS color:
#fffafa
orrgb(255,250,250)
.Declaration
Swift
public static let snow: Color
-
Honeydew standard CSS color:
#f0fff0
orrgb(240,255,240)
.Declaration
Swift
public static let honeydew: Color
-
Mint cream standard CSS color:
#f5fffa
orrgb(245,255,250)
.Declaration
Swift
public static let mintCream: Color
-
Azure standard CSS color:
#f0ffff
orrgb(240,255,255)
.Declaration
Swift
public static let azure: Color
-
Alice blue standard CSS color:
#f0f8ff
orrgb(240,248,255)
.Declaration
Swift
public static let aliceBlue: Color
-
Ghost white standard CSS color:
#f8f8ff
orrgb(248,248,255)
.Declaration
Swift
public static let ghostWhite: Color
-
White smoke standard CSS color:
#f5f5f5
orrgb(245,245,245)
.Declaration
Swift
public static let whiteSmoke: Color
-
Seashell standard CSS color:
#fff5ee
orrgb(255,245,238)
.Declaration
Swift
public static let seashell: Color
-
Beige standard CSS color:
#f5f5dc
orrgb(245,245,220)
.Declaration
Swift
public static let beige: Color
-
Old lace standard CSS color:
#fdf5e6
orrgb(253,245,230)
.Declaration
Swift
public static let oldLace: Color
-
Floral white standard CSS color:
#fffaf0
orrgb(255,250,240)
.Declaration
Swift
public static let floralWhite: Color
-
Ivory standard CSS color:
#fffff0
orrgb(255,255,240)
.Declaration
Swift
public static let ivory: Color
-
Antique white standard CSS color:
#faebd7
orrgb(250,235,215)
.Declaration
Swift
public static let antiqueWhite: Color
-
Linen standard CSS color:
#faf0e6
orrgb(250,240,230)
.Declaration
Swift
public static let linen: Color
-
Lavender blush standard CSS color:
#fff0f5
orrgb(255,240,245)
.Declaration
Swift
public static let lavenderBlush: Color
-
Misty rose standard CSS color:
#ffe4e1
orrgb(255,228,225)
.Declaration
Swift
public static let mistyRose: Color
-
Gainsboro standard CSS color:
#dcdcdc
orrgb(220,220,220)
.Declaration
Swift
public static let gainsboro: Color
-
Light gray standard CSS color:
#d3d3d3
orrgb(211,211,211)
.Declaration
Swift
public static let lightGray: Color
-
Silver standard CSS color:
#c0c0c0
orrgb(192,192,192)
.Declaration
Swift
public static let silver: Color
-
Dark gray standard CSS color:
#a9a9a9
orrgb(169,169,169)
.Declaration
Swift
public static let darkGray: Color
-
Gray standard CSS color:
#808080
orrgb(128,128,128)
.Declaration
Swift
public static let gray: Color
-
Dim gray standard CSS color:
#696969
orrgb(105,105,105)
.Declaration
Swift
public static let dimGray: Color
-
Light slate gray standard CSS color:
#778899
orrgb(119,136,153)
.Declaration
Swift
public static let lightSlateGray: Color
-
Slate gray standard CSS color:
#708090
orrgb(112,128,144)
.Declaration
Swift
public static let slateGray: Color
-
Dark slate gray standard CSS color:
#2f4f4f
orrgb(47,79,79)
.Declaration
Swift
public static let darkSlateGray: Color
-
Black standard CSS color:
#000000
orrgb(0,0,0)
.Declaration
Swift
public static let black: Color
-
Transparent, invisible color.
Declaration
Swift
public static let transparent: Color
-
Undocumented
Declaration
Swift
case value(_: UInt32)
-
Undocumented
Declaration
Swift
case RGB(_: UInt8, _: UInt8, _: UInt8, _: Float? = nil)
-
Undocumented
Declaration
Swift
case HSL(_: Float, _: Float, _: Float, _: Float? = nil)
-
Undocumented
Declaration
Swift
case CSS(_: String, _: UInt32? = nil)
-
Declaration
Swift
public func encode(to encoder: Encoder) throws
-
Undocumented
Declaration
Swift
func debugQuickLookObject() -> AnyObject
-
Declaration
Swift
public var playgroundDescription: Any { get }
-
Declaration
Swift
public typealias IntegerLiteralType = UInt32
-
Declaration
Swift
public init(integerLiteral integer: UInt32)