Ios 屏幕上显示RGB作为基本颜色的UIColor
我使用Ios 屏幕上显示RGB作为基本颜色的UIColor,ios,ios6,uicolor,Ios,Ios6,Uicolor,我使用[uicolorWithred:green:blue:alpha:][/code>函数制作了一个颜色词典。但是,当在屏幕上调用和显示时,它们看起来与实际颜色完全不同,而更像基本的[UIColor yellowColor]功能。是否有一个库,我应该包括,以显示RGB颜色的实际色调 以下是我制作的字典,仅供参考: colorStorage = [NSDictionary dictionaryWithObjectsAndKeys: [UIColor col
[uicolorWithred:green:blue:alpha:][/code>函数制作了一个颜色词典。但是,当在屏幕上调用和显示时,它们看起来与实际颜色完全不同,而更像基本的[UIColor yellowColor]
功能。是否有一个库,我应该包括,以显示RGB颜色的实际色调
以下是我制作的字典,仅供参考:
colorStorage = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:229.0 green:43.0 blue:80.0 alpha:1.0], @"Amaranth",
[UIColor colorWithRed:225 green:191 blue:0 alpha:1.0], @"Amber",
[UIColor colorWithRed:239 green:222 blue:205 alpha:1.0], @"Almond",
[UIColor colorWithRed:205 green:149 blue:117 alpha:1.0], @"Antique brass",
[UIColor colorWithRed:0 green:128 blue:0 alpha:1.0], @"Ao",
[UIColor colorWithRed:141 green:182 blue:0 alpha:1.0], @"Apple green",
[UIColor colorWithRed:251 green:206 blue:177 alpha:1.0], @"Apricot",
[UIColor colorWithRed:135.0 green:169.0 blue:107.0 alpha:1.0], @"Asparagus",
[UIColor colorWithRed:0 green:127 blue:255 alpha:1.0], @"Azure",
[UIColor colorWithRed:225 green:32 blue:82 alpha:1.0], @"Awesome",
[UIColor colorWithRed:178 green:190 blue:181 alpha:1.0], @"Ash grey",
[UIColor colorWithRed:110 green:127 blue:128 alpha:1.0], @"AutoMetalSaurus", nil];
它们被称为:
for (id key in colorStorage){
UIButton *colorButton = [UIButton buttonWithType:UIButtonTypeCustom];
[colorButton setTitle:key forState:UIControlStateNormal];
//additional code here...
colorButton.backgroundColor = [colorStorage objectForKey:key];
colorButton.tag = i;
[self.colorPicker addSubview:colorButton];
i = i + 1;
}
如上所述,始终将RGB值除以255.0。我第一次学习的时候也犯了这个错误
colorStorage = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:229.0/255.0 green:43.0/255.0 blue:80.0/255.0 alpha:1.0], @"Amaranth",
[UIColor colorWithRed:225.0/255.0 green:191.0/255.0 blue:0.0/255.0 alpha:1.0], @"Amber",
[UIColor colorWithRed:239.0/255.0 green:222.0/255.0 blue:205.0/255.0 alpha:1.0], @"Almond",
[UIColor colorWithRed:205.0/255.0 green:149.0/255.0 blue:117.0/255.0 alpha:1.0], @"Antique brass",
[UIColor colorWithRed:0.0/255.0 green:128.0/255.0 blue:0.0/255.0 alpha:1.0], @"Ao",
[UIColor colorWithRed:141.0/255.0 green:182.0/255.0 blue:0.0/255.0 alpha:1.0], @"Apple green",
[UIColor colorWithRed:251.0/255.0 green:206.0/255.0 blue:177.0/255.0 alpha:1.0], @"Apricot",
[UIColor colorWithRed:135.0/255.0 green:169.0/255.0 blue:107.0/255.0 alpha:1.0], @"Asparagus",
[UIColor colorWithRed:0.0/255.0 green:127.0/255.0 blue:255.0/255.0 alpha:1.0], @"Azure",
[UIColor colorWithRed:225.0/255.0 green:32.0/255.0 blue:82.0/255.0 alpha:1.0], @"Awesome",
[UIColor colorWithRed:178.0/255.0 green:190.0/255.0 blue:181.0/255.0 alpha:1.0], @"Ash grey",
[UIColor colorWithRed:110.0/255.0 green:127.0/255.0 blue:128.0/255.0 alpha:1.0], @"AutoMetalSaurus", nil];
颜色需要是0.0到1.0,就像alpha一样。将每个值除以255.0。可能重复的值就成功了!感谢你在所有这些255.0英寸的地方进驻!