You are taking an entirely wrong approach.
As a beginner, if you find yourself in drawing code (drawAtPoint:
, drawInRect:
etc.), you are almost certainly in the wrong place.
Especially for things like loading and displaying images, iOS does almost all the work for you, so you really don't have to draw anything yourself.
Please do not take this the wrong way, but do yourself a big favor and get a good introductory book on the subject. The books from the Big Nerd Ranch Guide series are excellent, and very well worth the money.
EDIT:
If you really do not want to get a book (please, for your own sake, get a book - I did, and I'm very glad I did), here's a quick way that should work.
You had the right idea in creating a UIImageView
, but you're using it wrong.
You very probably have a UIViewController
somewhere in your app. Find (or create) the - (void)viewDidLoad
method, and display your image from there:
- (void)viewDidLoad
{
UIImage *myImage = [UIImage imageNamed:@"Empty"]; //you can leave out PNG.
UIImageView *myFirstImageView = [[UIImageView alloc] initWithImage:myImage]; //this automatically gives the UIImageView the correct height and width
[self.view addSubview:myFirstImageView]; //That's all. UIKit will handle displaying the imageView automatically.
}
This will display the image in the upper left hand corner of the screen.
You can easily move it around by inserting the following line somewhere after UIImageView *myFirst...
:
myFirstImageView.center = CGPointMake(210.0, 345.0);
Did I mention the Big Nerd Ranch books are great to learn about iOS development, and are also even fun to read?
Also, the official documentation is very good (though not as fun or easy to read, and doesn't explain as much).