开发者

iPhone : How to use loop to generator a 256 color table in iphone?

I try to show 256 colors in iphone or even more colors

At first ,I use photoshop to generator some si开发者_如何学编程mple color png file

Than I add this png to an array and set it as a button picture

This is what I done now

This is the code how I add color into array

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];

Than I add this to button image

This is the result on my simulator , but this is not a good solution

iPhone : How to use loop to generator a 256 color table in iphone?

It waste too many time to add png file (also waste iphone memory...)

Does anyone can help me to figure this problem ???

MANY THANKS : )


if you just want to simply showing colors, you can subclassing UIView and override drawRect:

code is something like this:

    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

    }


You could load only one black and white png and then tint the color of the image as shown in this question below... How would I tint an image programmatically on the iPhone?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜