UIGraphicsGetImageFromCurrentImageContext memory leak with previews

The problem is this: UIGraphicsGetImageFromCurrentImageContext() returns an autoreleased UIImage. The autorelease pool holds on to this image until your code returns control to the runloop, which you do not do for a long time. To solve this problem, you would have to create and drain a fresh autorelease pool on every iteration (or every few … Read more

Changing UIImage color

Since iOS 7, this is the most simple way of doing it. Objective-C: theImageView.image = [theImageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; [theImageView setTintColor:[UIColor redColor]]; Swift 2.0: theImageView.image = theImageView.image?.imageWithRenderingMode(.AlwaysTemplate) theImageView.tintColor = UIColor.magentaColor() Swift 4.0: theImageView.image = theImageView.image?.withRenderingMode(.alwaysTemplate) theImageView.tintColor = .magenta Storyboard: First configure the image as template ( on right bar – Render as) in your assets. Then the … Read more

Cut transparent hole in UIView

This is my implementation (as I did needed a view with transparent parts): Header (.h) file: // Subclasses UIview to draw transparent rects inside the view #import <UIKit/UIKit.h> @interface PartialTransparentView : UIView { NSArray *rectsArray; UIColor *backgroundColor; } – (id)initWithFrame:(CGRect)frame backgroundColor:(UIColor*)color andTransparentRects:(NSArray*)rects; @end Implementation (.m) file: #import “PartialTransparentView.h” #import <QuartzCore/QuartzCore.h> @implementation PartialTransparentView – (id)initWithFrame:(CGRect)frame backgroundColor:(UIColor*)color … Read more