How to create a blank transparent png in Objective-C?
Objective CIosUiimageObjective C Problem Overview
How can I create a blank png UIImage in Objective C programmatically (let's say 36x36 px)?
Thanks :)
Objective C Solutions
Solution 1 - Objective C
You can open an image context, and then harvest its content immediately, without drawing anything into it. This should produce a blank 36x36
UIImage
:
UIGraphicsBeginImageContextWithOptions(CGSizeMake(36, 36), NO, 0.0);
UIImage *blank = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Solution 2 - Objective C
let img = UIImage() // size does not matter for a blank transparent image
When using a blank transparent image, its size does not matter, and I think the imageView.contentMode
might be any scalable value, or set it to UIView.ContentMode.scaleAspectFit
or UIView.ContentMode.scaleAspectFill
if needed.