Reputation: 703
I am new to programming and developing my first application, but I want to know that how can I display image to imageView.
Upvotes: 2
Views: 3736
Reputation: 15639
Programmatically :
From http://www.iphoneexamples.com/:
CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 109.0f);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"myImage.png"]];
myImage.opaque = YES; // explicitly opaque for performance
[self.view addSubview:myImage];
[myImage release];
Where myImage.png is an png format image which you will import to your resources folder.
Using Nib(Xib File):
Upvotes: 5
Reputation: 10172
UIImageView *imageView=[[UIImageView alloc] init];
[imageView setImage:[UIImage imageNamed:@"yourImage.png"]];
(If you have created imageView from IB and have outlet-ed it then ignore First Line)
Upvotes: 0
Reputation: 14113
// First way
myImage.image = [UIImage imageNamed:@"myImage.png"];
// Second way
NSString *fullpath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/myImage.png"];
myImage.image = [UIImage imageWithContentsOfFile:fullpath];
Check out UIImageView class reference here
Upvotes: 1
Reputation: 42093
Read http://www.iphoneexamples.com/
CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 109.0f);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"myImage.png"]];
myImage.opaque = YES; // explicitly opaque for performance
[self.view addSubview:myImage];
[myImage release];
Upvotes: 0