Aadil
Aadil

Reputation: 703

how to display Image in ImageView?

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

Answers (5)

Swastik
Swastik

Reputation: 2425

Try it using:

imgView.image = [UIImage imageNamed:@"test.png"];

Upvotes: 0

Chatar Veer Suthar
Chatar Veer Suthar

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):

  • Open your.xib file.
  • Go to Tools -> Library.
  • Drag and drop one UIImageView on your .xib.
  • Open Attribute Inspector of the ImageView(Press Cmd + 1).
  • You'll get one Image property. Set the image you want from your Resource folder using the drop-down list.
  • There you got it. :-)

Upvotes: 5

rptwsthi
rptwsthi

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

Nitish
Nitish

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

Naveed
Naveed

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

Related Questions