1

我使用该[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;
    }
4

1 回答 1

3

如前所述,始终将 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];
于 2013-07-23T01:40:17.537 回答