gpt4 book ai didi

ios - 具有 RGB 的 UIColors 在屏幕上显示为基本颜色

转载 作者:行者123 更新时间:2023-12-01 19:09:09 24 4
gpt4 key购买 nike

我使用 [UIColor colorWithRed: green: blue: alpha: ] 制作了一个颜色字典功能。但是,当调用并显示在屏幕上时,它们看起来与实际颜色完全不同,而是类似于基本的 [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];

关于ios - 具有 RGB 的 UIColors 在屏幕上显示为基本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17800098/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com