改变iphone sdk中的图像颜色

use*_*099 6 cocoa-touch image objective-c uicolor ios

我有一个图像,我想通过编程方式更改该图像的颜色.

在此输入图像描述

&我想改变这一形象的颜色

在此输入图像描述

Par*_*shi 13

更新:

使用这种方法......

-(UIImage *)imageNamed:(NSString *)name withColor:(UIColor *)color {
    // load the image

    UIImage *img = [UIImage imageNamed:name];

    // begin a new image context, to draw our colored image onto
    UIGraphicsBeginImageContext(img.size);

    // get a reference to that context we created
    CGContextRef context = UIGraphicsGetCurrentContext();

    // set the fill color
    [color setFill];

    // translate/flip the graphics context (for transforming from CG* coords to UI* coords
    CGContextTranslateCTM(context, 0, img.size.height);
    CGContextScaleCTM(context, 1.0, -1.0);

    // set the blend mode to color burn, and the original image
    CGContextSetBlendMode(context, kCGBlendModeColorBurn);
    CGRect rect = CGRectMake(0, 0, img.size.width, img.size.height);
    CGContextDrawImage(context, rect, img.CGImage);

    // set a mask that matches the shape of the image, then draw (color burn) a colored rectangle
    CGContextClipToMask(context, rect, img.CGImage);
    CGContextAddRect(context, rect);
    CGContextDrawPath(context,kCGPathFill);

    // generate a new UIImage from the graphics context we drew onto
    UIImage *coloredImg = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    //return the color-burned image
    return coloredImg;
}
Run Code Online (Sandbox Code Playgroud)

像下面那样用它...

yourImageView.image = [self imageNamed:@"yourImageName" withColor:[UIColor orangeColor]];
Run Code Online (Sandbox Code Playgroud)

希望这对你有帮助.....