Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display local image in UIImageView

Tags:

How do I display an image in the UIImageView component from the hard drive?

I have a local folder called "images" and would like to access it via a relative path, since I want to package the images with the app.

like image 364
mirzahat Avatar asked Jul 13 '11 05:07

mirzahat


People also ask

What is the difference between UIImage and UIImageView?

UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage . Save this answer.


2 Answers

To load image from somewhere on your drive use:

UIImage * myImage = [UIImage imageWithContentsOfFile: @"../images/1.png"]; 

Or add image to the Xcode project and use:

UIImage * myImage = [UIImage imageNamed: @"1.png"]; 

After that add image to imageview:

UIImageView * myImageView = [[UIImageView alloc] initWithImage: myImage]; 
like image 196
Valerii Pavlov Avatar answered Sep 18 '22 20:09

Valerii Pavlov


You dont need to give any path as long as the image is in your resources folder.

You can display that image in the imageView using this.

yourImageView.image = [UIImage imageNamed:@"something.png"]; 
like image 21
Robin Avatar answered Sep 20 '22 20:09

Robin