3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ブラウザで名前が定義されている140色をSwiftで定義する

Last updated at Posted at 2019-07-27

アプリを作成する毎に、Swiftで色定義を毎回作成してはいませんか?
標準的な定義と色見本があれば、デザイナーさんやクライアントさんとの色に関するやりとりが少なくできるのではないかと考えて少しググってみました。
結果、軽く調べた感じではSwiftの定義は無くて(誰も作ってなくて)代わりに下記のような素敵なサイトを発見しました。

原色大辞典

コード書いてあるし、名前があるのが何より良いです。

色見本と言えば個人的にはPantone Colorとかかなと思っていましたが、今やブラウザーの色定義ですよ。やはり!

というわけで、出来上がったのが下記のコードです。
Appleがすでに定義しているものはコメントアウトしています。

作っているうちに、あれ?これ #colorLiteral の方が良くない?と思ったので、
次回作ってみます。

Swift

import UIKit

public extension UIColor {

    //static let black = { UIColor(hex: 0x000000) }()
    static let aliceblue = { UIColor(hex: 0xf0f8ff) }()
    static let darkcyan = { UIColor(hex: 0x008b8b) }()
    static let lightyellow = { UIColor(hex: 0xffffe0) }()
    static let coral = { UIColor(hex: 0xff7f50) }()
    static let dimgray = { UIColor(hex: 0x696969) }()
    static let lavender = { UIColor(hex: 0xe6e6fa) }()
    static let teal = { UIColor(hex: 0x008080) }()
    static let lightgoldenrodyellow = { UIColor(hex: 0xfafad2) }()
    static let tomato = { UIColor(hex: 0xff6347) }()
    //static let gray = {UIColor(hex: 0x808080) }()
    static let lightsteelblue = { UIColor(hex: 0xb0c4de) }()
    static let darkslategray = { UIColor(hex: 0x2f4f4f) }()
    static let lemonchiffon = { UIColor(hex: 0xfffacd) }()
    static let orangered = { UIColor(hex: 0xff4500) }()
    //static let darkgray = { UIColor(hex: 0xa9a9a9) }()
    static let lightslategray = { UIColor(hex: 0x778899) }()
    static let darkgreen = { UIColor(hex: 0x006400) }()
    static let wheat = { UIColor(hex: 0xf5deb3) }()
    //static let red = {UIColor(hex: 0xff0000) }()
    static let silver = { UIColor(hex: 0xc0c0c0) }()
    static let slategray = { UIColor(hex: 0x708090) }()
    //static let green = { UIColor(hex: 0x008000) }()
    static let burlywood = { UIColor(hex: 0xdeb887) }()
    static let crimson = { UIColor(hex: 0xdc143c) }()
    //static let lightgray = { UIColor(hex: 0xd3d3d3) }()
    static let steelblue = { UIColor(hex: 0x4682b4) }()
    static let forestgreen = { UIColor(hex: 0x228b22) }()
    static let tan = { UIColor(hex: 0xd2b48c) }()
    static let mediumvioletred = { UIColor(hex: 0xc71585) }()
    static let gainsboro = { UIColor(hex: 0xdcdcdc) }()
    static let royalblue = { UIColor(hex: 0x4169e1) }()
    static let seagreen = { UIColor(hex: 0x2e8b57) }()
    static let khaki = { UIColor(hex: 0xf0e68c) }()
    static let deeppink = { UIColor(hex: 0xff1493) }()
    static let whitesmoke = { UIColor(hex: 0xf5f5f5) }()
    static let midnightblue = { UIColor(hex: 0x191970) }()
    static let mediumseagreen = { UIColor(hex: 0x3cb371) }()
    //static let yellow = { UIColor(hex: 0xffff00) }()
    static let hotpink = { UIColor(hex: 0xff69b4) }()
    //static let white = {UIColor(hex: 0xffffff) }()
    static let navy = { UIColor(hex: 0x000080) }()
    static let mediumaquamarine = { UIColor(hex: 0x66cdaa) }()
    static let gold = { UIColor(hex: 0xffd700) }()
    static let palevioletred = { UIColor(hex: 0xdb7093) }()
    static let snow = { UIColor(hex: 0xfffafa) }()
    static let darkblue = { UIColor(hex: 0x00008b) }()
    static let darkseagreen = { UIColor(hex: 0x8fbc8f) }()
    //static let orange = { UIColor(hex: 0xffa500) }()
    static let pink = { UIColor(hex: 0xffc0cb) }()
    static let ghostwhite = { UIColor(hex: 0xf8f8ff) }()
    static let mediumblue = { UIColor(hex: 0x0000cd) }()
    static let aquamarine = { UIColor(hex: 0x7fffd4) }()
    static let sandybrown = { UIColor(hex: 0xf4a460) }()
    static let lightpink = { UIColor(hex: 0xffb6c1) }()
    static let floralwhite = { UIColor(hex: 0xfffaf0) }()
    //static let blue = {UIColor(hex: 0x0000ff) }()
    static let palegreen = { UIColor(hex: 0x98fb98) }()
    static let darkorange = { UIColor(hex: 0xff8c00) }()
    static let thistle = { UIColor(hex: 0xd8bfd8) }()
    static let linen = { UIColor(hex: 0xfaf0e6) }()
    static let dodgerblue = { UIColor(hex: 0x1e90ff) }()
    static let lightgreen = { UIColor(hex: 0x90ee90) }()
    static let goldenrod = { UIColor(hex: 0xdaa520) }()
    //static let magenta = { UIColor(hex: 0xff00ff) }()
    static let antiquewhite = { UIColor(hex: 0xfaebd7) }()
    static let cornflowerblue = { UIColor(hex: 0x6495ed) }()
    static let springgreen = { UIColor(hex: 0x00ff7f) }()
    static let peru = { UIColor(hex: 0xcd853f) }()
    static let fuchsia = { UIColor(hex: 0xff00ff) }()
    static let papayawhip = { UIColor(hex: 0xffefd5) }()
    static let deepskyblue = { UIColor(hex: 0x00bfff) }()
    static let mediumspringgreen = { UIColor(hex: 0x00fa9a) }()
    static let darkgoldenrod = { UIColor(hex: 0xb8860b) }()
    static let violet = { UIColor(hex: 0xee82ee) }()
    static let blanchedalmond = { UIColor(hex: 0xffebcd) }()
    static let lightskyblue = { UIColor(hex: 0x87cefa) }()
    static let lawngreen = { UIColor(hex: 0x7cfc00) }()
    static let chocolate = { UIColor(hex: 0xd2691e) }()
    static let plum = { UIColor(hex: 0xdda0dd) }()
    static let bisque = { UIColor(hex: 0xffe4c4) }()
    static let skyblue = { UIColor(hex: 0x87ceeb) }()
    static let chartreuse = { UIColor(hex: 0x7fff00) }()
    static let sienna = { UIColor(hex: 0xa0522d) }()
    static let orchid = { UIColor(hex: 0xda70d6) }()
    static let moccasin = { UIColor(hex: 0xffe4b5) }()
    static let lightblue = { UIColor(hex: 0xadd8e6) }()
    static let greenyellow = { UIColor(hex: 0xadff2f) }()
    static let saddlebrown = { UIColor(hex: 0x8b4513) }()
    static let mediumorchid = { UIColor(hex: 0xba55d3) }()
    static let navajowhite = { UIColor(hex: 0xffdead) }()
    static let powderblue = { UIColor(hex: 0xb0e0e6) }()
    static let lime = { UIColor(hex: 0x00ff00) }()
    static let maroon = { UIColor(hex: 0x800000) }()
    static let darkorchid = { UIColor(hex: 0x9932cc) }()
    static let peachpuff = { UIColor(hex: 0xffdab9) }()
    static let paleturquoise = { UIColor(hex: 0xafeeee) }()
    static let limegreen = { UIColor(hex: 0x32cd32) }()
    static let darkred = { UIColor(hex: 0x8b0000) }()
    static let darkviolet = { UIColor(hex: 0x9400d3) }()
    static let mistyrose = { UIColor(hex: 0xffe4e1) }()
    static let lightcyan = { UIColor(hex: 0xe0ffff) }()
    static let yellowgreen = { UIColor(hex: 0x9acd32) }()
    //static let brown = { UIColor(hex: 0xa52a2a) }()
    static let darkmagenta = { UIColor(hex: 0x8b008b) }()
    static let lavenderblush = { UIColor(hex: 0xfff0f5) }()
    //static let cyan = { UIColor(hex: 0x00ffff) }()
    static let darkolivegreen = { UIColor(hex: 0x556b2f) }()
    static let firebrick = { UIColor(hex: 0xb22222) }()
    //static let purple = { UIColor(hex: 0x800080) }()
    static let seashell = { UIColor(hex: 0xfff5ee) }()
    static let aqua = { UIColor(hex: 0x00ffff) }()
    static let olivedrab = { UIColor(hex: 0x6b8e23) }()
    static let indianred = { UIColor(hex: 0xcd5c5c) }()
    static let indigo = { UIColor(hex: 0x4b0082) }()
    static let oldlace = { UIColor(hex: 0xfdf5e6) }()
    static let turquoise = { UIColor(hex: 0x40e0d0) }()
    static let olive = { UIColor(hex: 0x808000) }()
    static let rosybrown = { UIColor(hex: 0xbc8f8f) }()
    static let darkslateblue = { UIColor(hex: 0x483d8b) }()
    static let ivory = { UIColor(hex: 0xfffff0) }()
    static let mediumturquoise = { UIColor(hex: 0x48d1cc) }()
    static let darkkhaki = { UIColor(hex: 0xbdb76b) }()
    static let darksalmon = { UIColor(hex: 0xe9967a) }()
    static let blueviolet = { UIColor(hex: 0x8a2be2) }()
    static let honeydew = { UIColor(hex: 0xf0fff0) }()
    static let darkturquoise = { UIColor(hex: 0x00ced1) }()
    static let palegoldenrod = { UIColor(hex: 0xeee8aa) }()
    static let lightcoral = { UIColor(hex: 0xf08080) }()
    static let mediumpurple = { UIColor(hex: 0x9370db) }()
    static let mintcream = { UIColor(hex: 0xf5fffa) }()
    static let lightseagreen = { UIColor(hex: 0x20b2aa) }()
    static let cornsilk = { UIColor(hex: 0xfff8dc) }()
    static let salmon = { UIColor(hex: 0xfa8072) }()
    static let slateblue = { UIColor(hex: 0x6a5acd) }()
    static let azure = { UIColor(hex: 0xf0ffff) }()
    static let cadetblue = { UIColor(hex: 0x5f9ea0) }()
    static let beige = { UIColor(hex: 0xf5f5dc) }()
    static let lightsalmon = { UIColor(hex: 0xffa07a) }()
    static let mediumslateblue = { UIColor(hex: 0x7b68ee) }()
}

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?