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

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

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


当前回答

在设置颜色时,您可以像这样设置颜色

[UIColor colorWithRed:19/255.0 green:144/255.0 blue:255/255.0 alpha:1.0]

其他回答

请不要干扰视野。tintColor或扩展,但简单地使用这个:

UIColor.systemBlue

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

// 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

使用下面的代码自动获取颜色:

static let DefaultButtonColor = UIButton(type: UIButtonType.System).titleColorForState(.Normal)!

下面是一个简单的方法来获得默认的系统色调颜色:

+ (UIColor*)defaultSystemTintColor
{
   static UIColor* systemTintColor = nil;
   static dispatch_once_t onceToken;
   dispatch_once(&onceToken, ^{
      UIView* view = [[UIView alloc] init];
      systemTintColor = view.tintColor;
   });
   return systemTintColor;
}

颜色编码

#007AFF

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

ps. iOS, Swift