如何编写自定义颜色编码?

时间:2013-12-26 07:40:51

标签: objective-c ios7 xcode5

我在我的 viewDidLoad 方法中为我的 UserCreationViewController

使用此代码
NSDictionary *textAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                [UIColor greenColor],NSForegroundColorAttributeName,
                                [UIColor blackColor],NSBackgroundColorAttributeName,nil];

self.navigationController.navigationBar.titleTextAttributes = textAttributes;
self.title = @"User Creation";

我想知道的是,我明白我可以将UIColor更改为redColor,yellowColor(等等),我是如何编写自定义“颜色好”颜色的。

换句话说如果这个navigationBar标题是从颜色井中挑选出的自定义颜色,我如何设置颜色?

1 个答案:

答案 0 :(得分:1)

您可以使用以下代码:

UIColor *customColor = [UIColor colorWithRed:155.0/255.0 green:10.0/255.0 blue:50.0/255.0 alpha:1.0];

UIColor *customColor = [UIColor colorWithHue: 0.667 saturation: 1.0 brightness: 1.0 alpha: 1.0];

More info.