Reputation: 196
I'm new to objective-C programming for iOS. I'm struggling with a really simple task, drawing an image with code (not just including it in 'interface builder'). Here's the part of my code where I'm trying to put my image into the view:
UIImage *image = [UIImage imageNamed:@"Note.png"];
[image drawAtPoint:CGPointZero];
Simple. I have also tried with some retain and release commands, and even tried to include a second view on top of the old, to draw the image in. Without luck.
Thanks, John.
Upvotes: 0
Views: 1779
Reputation: 3664
The code you posted needs to go in drawRect. Just before drawRect is called, that part of your view is effectively erased, meaning you need to redraw whatever is in the rect that is passed as an argument.
(Note: if you value code simplicity over performance, you can draw the entire view in drawRect rather than only drawing the part that was requested to be drawn.)
Upvotes: 1
Reputation: 9543
Where are you doing this? drawAtPoint
will require there to be a valid current drawing context. Most commonly you should call it from inside some view's drawRect
method.
If that's correct, check that:
size
makes sense[image drawInRect:[yourView bounds]]
If all those are so, then you've got an interesting problem. Otherwise, either your image is duff or you're drawing at the wrong time.
Upvotes: 2