Difference between UIImage and UIImageView

后端 未结 8 707
予麋鹿
予麋鹿 2021-01-31 16:24

What is the difference between UIImage and UIImageView? Can someone explain it with an example?

8条回答
  •  囚心锁ツ
    2021-01-31 16:40

    In short: You create an instance of UIImage object to hold image's data, like this:

     NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"/picture.jpg"]; //assuming your image is in your app's bundle
    UIImage *img = [[UIImage alloc]initWithContentsOfFile:sourcePath];
    

    You then create an instance of UIImageView either through IB or code to display your image on the screen, like this:

    [imageView1 setImage:img];  //assume you already create an instance of UIImageView named imageView1
    

提交回复
热议问题