这是......的摘录
//
// 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
令人难以置信的是,他们不包括"标准Apple'按钮蓝'" ........
在项目中,我们总是这样:但这有点疯狂猜测。
#define APPLEBLUE [UIColor \
colorWithRed:0/255.0 green:122/255.0 blue:255/255.0 alpha:1.0]
或者,你可以做一些非常复杂的事情.........
@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;
}
看起来几乎令人难以置信的是,没有一种更简单的方法可以回归到标准的Apple控制蓝色"用于按钮和文字颜色。
这是Android程序员嘲笑我们的事情:/有没有人知道更简单的方法?我真的希望我错过了一些明显的东西。干杯
答案 0 :(得分:25)
有点晚了,但您可以在Apple的Human interface guidelines中找到颜色值。
蓝色为(R, G, B) = (0, 122, 255) = #007AFF
为方便起见,我创建了一个带有UIColor扩展名的GIST。
答案 1 :(得分:12)
试试数字色度计?它似乎在想(14,122,254)。
然后添加一个类别:
@implementation UIColor (MyColors)
+ (UIColor*)appleBlue {
return [UIColor colorWithRed:14.0/255 green:122.0/255 blue:254.0/255 alpha:1.0];
}
@end
答案 2 :(得分:4)
将此用于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)
}
}
答案 3 :(得分:3)
从iOS 7开始,您可以简单地使用此功能:
UIColor.systemBlue
答案 4 :(得分:0)
如果您只是在寻找RGB十六进制代码,它就可以了:
'#0E7AFE'