1

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

应该给海洋颜色。

我发现当直接从对象(在我的例子中是按钮)属性中选择海洋颜色时,它的颜色并不完全相同:你知道是否有工具可以准确检测特定颜色的值吗?

4

3 回答 3

7

使用此扩展程序拥有所有颜色

 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)
        }
}
于 2015-02-09T10:01:14.257 回答
3

颜色选择器会帮助你吗?在 Mac 上,我使用http://colorsnapper.com/,如果是网页,我使用https://chrome.google.com/webstore/detail/pendule

您可以将鼠标悬停在所需的颜色上,并获取十六进制代码。我会参考如何从十六进制字符串创建 UIColor?有关从十六进制转换为 UIColor 的详细信息,或使用这个方便的网络应用程序

(注意:ColorSnapper 不是免费的,但它确实有一个 iOS UIColor 选项,这将消除您必须自己从十六进制转换的需要)

于 2012-11-20T20:44:46.673 回答
3

以下是上述蒂姆肯特答案的略微修改版本。此版本使用类常量来避免在引用颜色时键入括号。

使用常量,而不是键入以下内容:

let myColor = UIColor.cantaloupe()

你可以输入这个:

let myColor = UIColor.cantaloupe

更新后的扩展如下所示:

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)
}

PS 还修复了拼写错误cantalope->cantaloupealuminium-> aluminum(如 XCode 中)并按字母顺序对颜色名称进行排序。但是,颜色代码未经过验证。

于 2019-03-11T03:58:35.050 回答