Display local image in UIImageView

mirzahat picture mirzahat · Jul 13, 2011 · Viewed 54.8k times · Source

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.

Answer

Valerii  Pavlov picture Valerii Pavlov · Jul 13, 2011

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];