1
votes

[UIColor colorWithRed:0.000 green:0.333 blue:0.557 alpha:1.000]

Should give the ocean color.

I see that it's not exactly the same color when select directly Ocean color from object (button in my case) property: do you know if there's a tool to detect exactly the value of a particular color ?

3

3 Answers

3
votes

Would a color picker help you? On the Mac, I use http://colorsnapper.com/, and if it's a webpage, I use https://chrome.google.com/webstore/detail/pendule.

You can hover over the desired color, and get the hex code. I would refer to How can I create a UIColor from a hex string? for details on converting from hex to UIColor, or use this handy web app.

(Note: ColorSnapper is not free, but it does have an iOS UIColor option that will eliminate the need for you to have to convert from hex yourself)

7
votes

Use this extension to have all colors

 extension UIColor {

        class func cantaloupe() -> UIColor {
            return UIColor(red:255/255, green:204/255, blue:102/255, alpha:1.0)
        }
        class func honeydew() -> UIColor {
            return UIColor(red:204/255, green:255/255, blue:102/255, alpha:1.0)
        }
        class func spindrift() -> UIColor {
            return UIColor(red:102/255, green:255/255, blue:204/255, alpha:1.0)
        }
        class func sky() -> UIColor {
            return UIColor(red:102/255, green:204/255, blue:255/255, alpha:1.0)
        }
        class func lavender() -> UIColor {
            return UIColor(red:204/255, green:102/255, blue:255/255, alpha:1.0)
        }
        class func carnation() -> UIColor {
            return UIColor(red:255/255, green:111/255, blue:207/255, alpha:1.0)
        }
        class func licorice() -> UIColor {
            return UIColor(red:0/255, green:0/255, blue:0/255, alpha:1.0)
        }
        class func snow() -> UIColor {
            return UIColor(red:255/255, green:255/255, blue:255/255, alpha:1.0)
        }
        class func salmon() -> UIColor {
            return UIColor(red:255/255, green:102/255, blue:102/255, alpha:1.0)
        }
        class func banana() -> UIColor {
            return UIColor(red:255/255, green:255/255, blue:102/255, alpha:1.0)
        }
        class func flora() -> UIColor {
            return UIColor(red:102/255, green:255/255, blue:102/255, alpha:1.0)
        }
        class func ice() -> UIColor {
            return UIColor(red:102/255, green:255/255, blue:255/255, alpha:1.0)
        }
        class func orchid() -> UIColor {
            return UIColor(red:102/255, green:102/255, blue:255/255, alpha:1.0)
        }
        class func bubblegum() -> UIColor {
            return UIColor(red:255/255, green:102/255, blue:255/255, alpha:1.0)
        }
        class func lead() -> UIColor {
            return UIColor(red:25/255, green:25/255, blue:25/255, alpha:1.0)
        }
        class func mercury() -> UIColor {
            return UIColor(red:230/255, green:230/255, blue:230/255, alpha:1.0)
        }
        class func tangerine() -> UIColor {
            return UIColor(red:255/255, green:128/255, blue:0/255, alpha:1.0)
        }
        class func lime() -> UIColor {
            return UIColor(red:128/255, green:255/255, blue:0/255, alpha:1.0)
        }
        class func seafoam() -> UIColor {
            return UIColor(red:0/255, green:255/255, blue:128/255, alpha:1.0)
        }
        class func aqua() -> UIColor {
            return UIColor(red:0/255, green:128/255, blue:255/255, alpha:1.0)
        }
        class func grape() -> UIColor {
            return UIColor(red:128/255, green:0/255, blue:255/255, alpha:1.0)
        }
        class func strawberry() -> UIColor {
            return UIColor(red:255/255, green:0/255, blue:128/255, alpha:1.0)
        }
        class func tungsten() -> UIColor {
            return UIColor(red:51/255, green:51/255, blue:51/255, alpha:1.0)
        }
        class func silver() -> UIColor {
            return UIColor(red:204/255, green:204/255, blue:204/255, alpha:1.0)
        }
        class func maraschino() -> UIColor {
            return UIColor(red:255/255, green:0/255, blue:0/255, alpha:1.0)
        }
        class func lemon() -> UIColor {
            return UIColor(red:255/255, green:255/255, blue:0/255, alpha:1.0)
        }
        class func spring() -> UIColor {
            return UIColor(red:0/255, green:255/255, blue:0/255, alpha:1.0)
        }
        class func turquoise() -> UIColor {
            return UIColor(red:0/255, green:255/255, blue:255/255, alpha:1.0)
        }
        class func blueberry() -> UIColor {
            return UIColor(red:0/255, green:0/255, blue:255/255, alpha:1.0)
        }
        class func magenta() -> UIColor {
            return UIColor(red:255/255, green:0/255, blue:255/255, alpha:1.0)
        }
        class func iron() -> UIColor {
            return UIColor(red:76/255, green:76/255, blue:76/255, alpha:1.0)
        }
        class func magnesium() -> UIColor {
            return UIColor(red:179/255, green:179/255, blue:179/255, alpha:1.0)
        }
        class func mocha() -> UIColor {
            return UIColor(red:128/255, green:64/255, blue:0/255, alpha:1.0)
        }
        class func fern() -> UIColor {
            return UIColor(red:64/255, green:128/255, blue:0/255, alpha:1.0)
        }
        class func moss() -> UIColor {
            return UIColor(red:0/255, green:128/255, blue:64/255, alpha:1.0)
        }
        class func ocean() -> UIColor {
            return UIColor(red:0/255, green:64/255, blue:128/255, alpha:1.0)
        }
        class func eggplant() -> UIColor {
            return UIColor(red:64/255, green:0/255, blue:128/255, alpha:1.0)
        }
        class func maroon() -> UIColor {
            return UIColor(red:128/255, green:0/255, blue:64/255, alpha:1.0)
        }
        class func steel() -> UIColor {
            return UIColor(red:102/255, green:102/255, blue:102/255, alpha:1.0)
        }
        class func aluminium() -> UIColor {
            return UIColor(red:153/255, green:153/255, blue:153/255, alpha:1.0)
        }
        class func cayenne() -> UIColor {
            return UIColor(red:128/255, green:0/255, blue:0/255, alpha:1.0)
        }
        class func asparagus() -> UIColor {
            return UIColor(red:128/255, green:120/255, blue:0/255, alpha:1.0)
        }
        class func clover() -> UIColor {
            return UIColor(red:0/255, green:128/255, blue:0/255, alpha:1.0)
        }
        class func teal() -> UIColor {
            return UIColor(red:0/255, green:128/255, blue:128/255, alpha:1.0)
        }
        class func midnight() -> UIColor {
            return UIColor(red:0/255, green:0/255, blue:128/255, alpha:1.0)
        }
        class func plum() -> UIColor {
            return UIColor(red:128/255, green:0/255, blue:128/255, alpha:1.0)
        }
        class func tin() -> UIColor {
            return UIColor(red:127/255, green:127/255, blue:127/255, alpha:1.0)
        }
        class func nickel() -> UIColor {
            return UIColor(red:128/255, green:128/255, blue:128/255, alpha:1.0)
        }
}
3
votes

The following is a slightly modified version of Timm Kent's answer above. This version uses class constants to avoid typing parentheses when referencing a color.

With constants, instead of typing this:

let myColor = UIColor.cantaloupe()

You can type this:

let myColor = UIColor.cantaloupe

The updated extension looks like this:

import UIKit

extension UIColor
{
    static let aluminum = UIColor(red:153/255, green:153/255, blue:153/255, alpha:1.0)
    static let aqua = UIColor(red:0/255, green:128/255, blue:255/255, alpha:1.0)
    static let asparagus = UIColor(red:128/255, green:120/255, blue:0/255, alpha:1.0)
    static let banana = UIColor(red:255/255, green:255/255, blue:102/255, alpha:1.0)
    static let blueberry = UIColor(red:0/255, green:0/255, blue:255/255, alpha:1.0)
    static let bubblegum = UIColor(red:255/255, green:102/255, blue:255/255, alpha:1.0)
    static let cantalope = UIColor(red:255/255, green:204/255, blue:102/255, alpha:1.0)
    static let carnation = UIColor(red:255/255, green:111/255, blue:207/255, alpha:1.0)
    static let cayenne = UIColor(red:128/255, green:0/255, blue:0/255, alpha:1.0)
    static let clover = UIColor(red:0/255, green:128/255, blue:0/255, alpha:1.0)
    static let eggplant = UIColor(red:64/255, green:0/255, blue:128/255, alpha:1.0)
    static let fern = UIColor(red:64/255, green:128/255, blue:0/255, alpha:1.0)
    static let flora = UIColor(red:102/255, green:255/255, blue:102/255, alpha:1.0)
    static let grape = UIColor(red:128/255, green:0/255, blue:255/255, alpha:1.0)
    static let honeydew = UIColor(red:204/255, green:255/255, blue:102/255, alpha:1.0)
    static let ice = UIColor(red:102/255, green:255/255, blue:255/255, alpha:1.0)
    static let iron = UIColor(red:76/255, green:76/255, blue:76/255, alpha:1.0)
    static let lavender = UIColor(red:204/255, green:102/255, blue:255/255, alpha:1.0)
    static let lead = UIColor(red:25/255, green:25/255, blue:25/255, alpha:1.0)
    static let lemon = UIColor(red:255/255, green:255/255, blue:0/255, alpha:1.0)
    static let licorice = UIColor(red:0/255, green:0/255, blue:0/255, alpha:1.0)
    static let lime = UIColor(red:128/255, green:255/255, blue:0/255, alpha:1.0)
    static let magenta = UIColor(red:255/255, green:0/255, blue:255/255, alpha:1.0)
    static let magnesium = UIColor(red:179/255, green:179/255, blue:179/255, alpha:1.0)
    static let maraschino = UIColor(red:255/255, green:0/255, blue:0/255, alpha:1.0)
    static let maroon = UIColor(red:128/255, green:0/255, blue:64/255, alpha:1.0)
    static let mercury = UIColor(red:230/255, green:230/255, blue:230/255, alpha:1.0)
    static let midnight = UIColor(red:0/255, green:0/255, blue:128/255, alpha:1.0)
    static let mocha = UIColor(red:128/255, green:64/255, blue:0/255, alpha:1.0)
    static let moss = UIColor(red:0/255, green:128/255, blue:64/255, alpha:1.0)
    static let nickel = UIColor(red:128/255, green:128/255, blue:128/255, alpha:1.0)
    static let ocean = UIColor(red:0/255, green:64/255, blue:128/255, alpha:1.0)
    static let orchid = UIColor(red:102/255, green:102/255, blue:255/255, alpha:1.0)
    static let plum = UIColor(red:128/255, green:0/255, blue:128/255, alpha:1.0)
    static let salmon = UIColor(red:255/255, green:102/255, blue:102/255, alpha:1.0)
    static let seafoam = UIColor(red:0/255, green:255/255, blue:128/255, alpha:1.0)
    static let silver = UIColor(red:204/255, green:204/255, blue:204/255, alpha:1.0)
    static let sky = UIColor(red:102/255, green:204/255, blue:255/255, alpha:1.0)
    static let snow = UIColor(red:255/255, green:255/255, blue:255/255, alpha:1.0)
    static let spindrift = UIColor(red:102/255, green:255/255, blue:204/255, alpha:1.0)
    static let spring = UIColor(red:0/255, green:255/255, blue:0/255, alpha:1.0)
    static let steel = UIColor(red:102/255, green:102/255, blue:102/255, alpha:1.0)
    static let strawberry = UIColor(red:255/255, green:0/255, blue:128/255, alpha:1.0)
    static let tangerine = UIColor(red:255/255, green:128/255, blue:0/255, alpha:1.0)
    static let teal = UIColor(red:0/255, green:128/255, blue:128/255, alpha:1.0)
    static let tin = UIColor(red:127/255, green:127/255, blue:127/255, alpha:1.0)
    static let tungsten = UIColor(red:51/255, green:51/255, blue:51/255, alpha:1.0)
    static let turquoise = UIColor(red:0/255, green:255/255, blue:255/255, alpha:1.0)
}

P.S. Also fixed typos cantalope -> cantaloupe and aluminium -> aluminum (as in XCode) and sorted color names alphabetically. Color codes are not verified though.