Display local image in UIImageView

后端 未结 4 1732
[愿得一人]
[愿得一人] 2021-01-01 12:09

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,

4条回答
  •  無奈伤痛
    2021-01-01 12:51

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

提交回复
热议问题