Search code examples
iosobjective-ciphoneimagesource

Display local image in UIImageView


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.


Solution

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