This isn’t what you probably thought it was to begin with. I know how to use UIImage’s, but I now need to know how to create a “blank” UIImage using:
CGRect screenRect = [self.view bounds];
Well, those dimensions. Anyway, I want to know how I can create a UIImage with those dimensions colored all white. No actual images here.
Is this even possible? I am sure it is, but maybe I am wrong.
Edit
This needs to be a “white” image. Not a blank one. 🙂
You need to use
CoreGraphics, as follows.The code creates a new
CoreGraphicsimage context with the options passed as parameters; size, opaqueness, and scale. By passing0for scale, iOS automatically chooses the appropriate value for the current device.Then, the context fill colour is set to
[UIColor whiteColor]. Immediately, the canvas is then actually filled with that color, by usingUIRectFill()and passing a rectangle which fills the canvas.A
UIImageis then created of the current context, and the context is closed. Therefore, the image variable contains aUIImageof the desired size, filled white.