Web*_*Lai 0 iphone colors objective-c ios
我尝试在iPhone中显示256种颜色甚至更多颜色
首先,我使用photoshop生成一些简单的颜色png文件
比我将这个png添加到一个数组并将其设置为按钮图片
这就是我现在所做的
这是我如何将颜色添加到数组中的代码
imgArray = [NSArray arrayWithObjects:
[UIImage imageNamed:@"Icon0.png"],
[UIImage imageNamed:@"Icon1.png"],
[UIImage imageNamed:@"Icon2.png"],
[UIImage imageNamed:@"Icon3.png"],
[UIImage imageNamed:@"Icon4.png"],
[UIImage imageNamed:@"Icon5.png"],
nil];
Run Code Online (Sandbox Code Playgroud)
比我添加到按钮图像
这是我的模拟器上的结果,但这不是一个好的解决方案

它浪费了太多时间来添加png文件(也浪费了iphone内存......)
有谁能帮我解决这个问题???
非常感谢 : )
如果你只想简单地显示颜色,你可以继承UIView并覆盖 drawRect:
代码是这样的:
CGFloat red, green, blue, x, y, width, height;
for (red = 0; red < 1; red += 1/8)
for (blue = 0; blue < 1; blue += 1/8)
for (green = 0; green < 1; green += 1/8) {
//update x and y
UIColor *color = [UIColor colorWithRed:red green:green blue:blue alpha:1]; //create the color by rgb value
[color setFill];
CGContextFillRect(context, CGRectMake(x, y, width, height)); //draw the rect
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
625 次 |
| 最近记录: |