ios 什么是标准的苹果蓝颜色?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24637812/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 01:16:05  来源:igfitidea点击:

What is the standard Apple blue colour?

iosuibuttonuicolor

提问by Fattie

Here's an extract from ...

这是摘自...

//
//  UIColor.h
//  UIKit
//
//  Copyright (c) 2005-2013, Apple Inc. All rights reserved.
//

 ........ 

// Some convenience methods to create colours.
// These colors will be as calibrated as possible.
// These colors are cached.
+ (UIColor *)blackColor;      // 0.0 white 
+ (UIColor *)darkGrayColor;   // 0.333 white 
+ (UIColor *)lightGrayColor;  // 0.667 white 
+ (UIColor *)whiteColor;      // 1.0 white 
+ (UIColor *)grayColor;       // 0.5 white 
+ (UIColor *)redColor;        // 1.0, 0.0, 0.0 RGB 
+ (UIColor *)greenColor;      // 0.0, 1.0, 0.0 RGB 
+ (UIColor *)blueColor;       // 0.0, 0.0, 1.0 RGB 
+ (UIColor *)cyanColor;       // 0.0, 1.0, 1.0 RGB 
+ (UIColor *)yellowColor;     // 1.0, 1.0, 0.0 RGB 
+ (UIColor *)magentaColor;    // 1.0, 0.0, 1.0 RGB 
+ (UIColor *)orangeColor;     // 1.0, 0.5, 0.0 RGB 
+ (UIColor *)purpleColor;     // 0.5, 0.0, 0.5 RGB 
+ (UIColor *)brownColor;      // 0.6, 0.4, 0.2 RGB 
+ (UIColor *)clearColor;      // 0.0 white, 0.0 alpha 

Incredibly, they do not include"standard Apple 'button blue'" ........

令人难以置信的是,它们不包括“标准的苹果‘蓝色按钮’”......

enter image description here

在此处输入图片说明

In projects, we always have this: but it's a bit of a wild guess.

在项目中,我们总是有这样的:但这有点疯狂的猜测。

#define APPLEBLUE [UIColor \
  colorWithRed:0/255.0 green:122/255.0 blue:255/255.0 alpha:1.0]

Alternately, you can do something insanely complex like this.........

或者,你可以做一些像这样疯狂复杂的事情.......

@implementation SomeButtons
{
UIColor *defaultColor;
}

-(id)initWithFrame:(CGRect)frame
    {
    defaultColor = [UIColor redColor];
    if(self = [super initWithFrame:frame])
        {
        for (UIView *v in self.subviews)
          if ([v isKindOfClass:[UIButton class]])
            defaultColor = [(UIButton *)v titleColorForState:UIControlStateNormal];
        }
    return self;
    }

-(id)initWithCoder:(NSCoder *)aCoder
    {
    if(self = [super initWithCoder:aCoder])
        {
        for (UIView *v in self.subviews)
          if ([v isKindOfClass:[UIButton class]])
            defaultColor = [(UIButton *)v titleColorForState:UIControlStateNormal];
        }
    return self;
    }

It seems almost unbelievable there is not, an easier way, to return to "standard Apple control blue" for button and text colors.

几乎令人难以置信的是,没有一种更简单的方法可以将按钮和文本颜色恢复为“标准 Apple 控制蓝色”。

This is the sort of thing Android programmers laugh at us about :/ Does anyone know an easier way? I really hope I'm missing something obvious. Cheers

这是Android程序员嘲笑我们的事情:/有人知道更简单的方法吗?我真的希望我错过了一些明显的东西。干杯

回答by David Rysanek

A bit late, but you can find the colour values in Apple's Human interface guidelines.

有点晚了,但您可以在 Apple 的人机界面指南 中找到颜色值。

The blue is (R, G, B) = (0, 122, 255) = #007AFF

蓝色的是 (R, G, B) = (0, 122, 255) = #007AFF

Apple colours

苹果色

I created a GISTwith UIColor extension for your convenience.

为了您的方便,我创建了一个带有 UIColor 扩展的GIST

回答by i_am_jorf

Try the digital color meter? It seems to think (14, 122, 254).

试试数字色度计?它似乎认为 (14, 122, 254)。

enter image description here

在此处输入图片说明

Then add a category:

然后添加一个类别:

@implementation UIColor (MyColors)

+ (UIColor*)appleBlue {
    return [UIColor colorWithRed:14.0/255 green:122.0/255 blue:254.0/255 alpha:1.0];
}

@end

回答by Roy K

Use this for swift:

快速使用它:

extension UIColor {
    static func appleBlue() -> UIColor {
        return UIColor.init(colorLiteralRed: 14.0/255, green: 122.0/255, blue: 254.0/255, alpha: 1.0)
    }
}