Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I just wrote a tutorial that will help with this. My approach gives you a copy of a UIImage, with the color alterations that you want. rpetrich's approach is great, but requires that you're creating a subclass. My approach is just a few lines of code that can be dropped in wherever you need them. <a href="http://coffeeshopped.com/2010/09/iphone-how-to-dynamically-color-a-uiimage" rel="nofollow noreferrer">http://coffeeshopped.com/2010/09/iphone-how-to-dynamically-color-a-uiimage</a></p> <pre><code>NSString *name = @"badge.png"; 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; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload