【发布时间】:2014-08-29 13:00:49
【问题描述】:
这是...的摘录
//
// 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 'button blue'”......
在项目中,我们总是有这样的:但这有点疯狂。
#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 程序员嘲笑我们的那种事情:/ 有谁知道更简单的方法吗?我真的希望我遗漏了一些明显的东西。干杯
【问题讨论】:
-
从 iOS7 开始,“标准蓝色”是视图的
tintColor。绝对不需要在应用程序的任何地方使用默认颜色。不,Apple 不会更改您应用的 tintColor。