我在我的应用程序中创建自定义元素,并希望与新iOS的外观和感觉相匹配。iOS 7向我们介绍了一种非常常见的浅蓝色,这是几个元素的默认颜色或色调,包括系统按钮、分段控件等。他们很容易使用IB选择颜色,如下所示:

但是,我还没有找到如何通过编程轻松地访问颜色。我检查了UIColor文档,在类本身中似乎没有任何用于蓝色系统颜色的访问器。

我的问题是:这种颜色有简单的访问器吗?[UIColor ?]之类的东西?如果不是,有人知道这种颜色的确切RGB值吗?


当前回答

根据UIButton的文档:

在iOS v7.0中,UIView的所有子类都从基类派生tintColor的行为。更多信息请参见UIView级别的tintColor讨论。

假设你在获取默认值之前不改变tintColor,你可以使用:

self.view.tintColor

其他回答

它似乎是[UIColor colorWithRed:0.0绿色:122.0/255.0蓝色:1.0 alpha:1.0]。

从iOS 7有一个API,你可以获得(并设置)色调颜色:

self.view.tintColor

或者如果你需要CGColor:

self.view.tintColor.CGColor

ui窗口。tintColor方法在iOS8中对我不起作用(它仍然是黑色的),所以我必须这样做:

let b = UIButton.buttonWithType(UIButtonType.System) as UIButton
var color = b.titleColorForState(.Normal)

这给了一个UIBarButtonItem中看到的适当的蓝色

颜色编码

#007AFF

你需要这个图书馆 https://github.com/thii/SwiftHEXColors

ps. iOS, Swift

本机扩展与预定义的系统颜色提供了你正在寻找的:

// System colors

extension UIColor {

   
    /* Some colors that are used by system elements and applications.
     * These return named colors whose values may vary between different contexts and releases.
     * Do not make assumptions about the color spaces or actual colors used.
     */
    
    ... 

    @available(iOS 7.0, *)
    open class var systemBlue: UIColor { get }
    ... 
}

你可以直接使用它:

myView.tintColor = .systemBlue