Alb*_*haw 10 arrays rows objective-c ios
我正在设置一个阵列,它在整个彩虹的颜色中都有一个过渡.现在我只是手动输入数组中的颜色,但手动输入的数量太多了......到目前为止我只是从0.25到0.5到0.75到1,依此类推,直到我从红色变为绿色到蓝色然后回来.(参见下面的代码)如何让阵列自动生成大于0.25 - > 0.5 - > 0.75但可能0.05 - > 0.10 - > 0.15 - > 0.20等颜色,等等......这是我的数组:
rainbowColors = [[NSArray alloc] initWithObjects:
[UIColor colorWithRed:1 green:0 blue:0 alpha:1],
[UIColor colorWithRed:1 green:0.25 blue:0 alpha:1],
[UIColor colorWithRed:1 green:0.5 blue:0 alpha:1],
[UIColor colorWithRed:1 green:0.75 blue:0 alpha:1],
[UIColor colorWithRed:1 green:1 blue:0 alpha:1],
[UIColor colorWithRed:0.75 green:1 blue:0 alpha:1],
[UIColor colorWithRed:0.5 green:1 blue:0 alpha:1],
[UIColor colorWithRed:0.25 green:1 blue:0 alpha:1],
[UIColor colorWithRed:0 green:1 blue:0 alpha:1],
[UIColor colorWithRed:0 green:1 blue:0.25 alpha:1],
[UIColor colorWithRed:0 green:1 blue:0.5 alpha:1],
[UIColor colorWithRed:0 green:1 blue:0.75 alpha:1],
[UIColor colorWithRed:0 green:1 blue:1 alpha:1],
[UIColor colorWithRed:0 green:0.75 blue:1 alpha:1],
[UIColor colorWithRed:0 green:0.5 blue:1 alpha:1],
[UIColor colorWithRed:0 green:0.25 blue:1 alpha:1],
[UIColor colorWithRed:0 green:0 blue:1 alpha:1],
[UIColor colorWithRed:0.25 green:0 blue:1 alpha:1],
[UIColor colorWithRed:0.5 green:0 blue:1 alpha:1],
[UIColor colorWithRed:0.75 green:0 blue:1 alpha:1],
[UIColor colorWithRed:1 green:0 blue:1 alpha:1],
[UIColor colorWithRed:1 green:0 blue:0.75 alpha:1],
[UIColor colorWithRed:1 green:0 blue:0.5 alpha:1],
[UIColor colorWithRed:1 green:0 blue:0.25 alpha:1],nil];
Run Code Online (Sandbox Code Playgroud)
BJ *_*mer 41
更简单,使用-[UIColor colorWithHue:saturation:brightness:alpha:]
,像这样:
NSMutableArray *colors = [NSMutableArray array];
float INCREMENT = 0.05;
for (float hue = 0.0; hue < 1.0; hue += INCREMENT) {
UIColor *color = [UIColor colorWithHue:hue
saturation:1.0
brightness:1.0
alpha:1.0];
[colors addObject:color];
}
Run Code Online (Sandbox Code Playgroud)
这允许您改变色调(或颜色)而不改变屏幕上颜色的亮度,这是您现在很可能不会保留的.写起来也简单得多,后来的读者也更清楚了.
归档时间: |
|
查看次数: |
10051 次 |
最近记录: |