Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was not able to find a proper solution to this and I needed a quick workaround. Below is a function which, given a UIImage, returns a new image which is darkened with a dark alpha fill. The context fill commands could be replaced with other draw or fill routines to provide different types of darkening.</p> <p>This is un-optimized and was made with minimal knowledge of the graphics api.</p> <p>You can use this function to set the UIControlStateHighlighted state image so that at least it will be darker.</p> <pre><code>+ (UIImage *)darkenedImageWithImage:(UIImage *)sourceImage { UIImage * darkenedImage = nil; if (sourceImage) { // drawing prep CGImageRef source = sourceImage.CGImage; CGRect drawRect = CGRectMake(0.f, 0.f, sourceImage.size.width, sourceImage.size.height); CGContextRef context = CGBitmapContextCreate(NULL, drawRect.size.width, drawRect.size.height, CGImageGetBitsPerComponent(source), CGImageGetBytesPerRow(source), CGImageGetColorSpace(source), CGImageGetBitmapInfo(source) ); // draw given image and then darken fill it CGContextDrawImage(context, drawRect, source); CGContextSetBlendMode(context, kCGBlendModeOverlay); CGContextSetRGBFillColor(context, 0.f, 0.f, 0.f, 0.5f); CGContextFillRect(context, drawRect); // get context result CGImageRef darkened = CGBitmapContextCreateImage(context); CGContextRelease(context); // convert to UIImage and preserve original orientation darkenedImage = [UIImage imageWithCGImage:darkened scale:1.f orientation:sourceImage.imageOrientation]; CGImageRelease(darkened); } return darkenedImage; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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