How to set image to UIImage

后端 未结 12 948
小蘑菇
小蘑菇 2020-12-14 06:20

How can I set image to UIImage object. For example:

UIImage *img = [[UIImage alloc] init];
[img setImage:[UIImage imageNamed:@\"anyImageName\"]]         


        
12条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-14 07:12

    Like vikingosgundo said, but keep in mind that if you use [UIImage imageNamed:image] then the image is cached and eats away memory. So unless you plan on using the same image in many places, you should load the image, with imageWithContentsOfFile: and imageWithData:

    This will save you significant memory and speeds up your app.

提交回复
热议问题