0

When I am developing apps in iOS before, I always put the image sources of the app at the root directory of the project, and then I will load them using [UIImage imageNamed:@"image.png"]. I did't even include various sizes and resolutions such as image@2x or image@3x. But I am afraid this is not a good practice, because I cannot deal with different screen resolutions.

Now, I want to make use of the Images.xcasset to store all my image sources so that I will be able to load just the bundle name, and hoping that the system will pick the image with the right resolution automatically. Therefore, I made a test and place my image set under Images.xcasset and named it as images, and then in my UIViewController.m I am trying to load the image by calling [UIImage imageName:images]. As a result, it didn't work. So I searched for an answer and found out that I should call [UIImage imageName:@"images60x60@2x.png"] in order to load the the 60pt @2x image.

But I think this still did not solve my problem, because I am still choosing which image to load. Is there a way to load the entire image set or load the image according to the resolution of the screen?

Please help. Many Thanks.

EDIT: Added Screen Shots

enter image description here

I use AppIcon as a test

enter image description here

JLT
  • 3,052
  • 9
  • 39
  • 86
  • Where did you fond `[UIImage imageName:images60x60@2x]`? That seems so wrong for normal image loading... – Swapnil Luktuke Aug 07 '15 at 07:47
  • @lukya from this answer: http://stackoverflow.com/questions/19587139/load-app-icon-from-xcassets – JLT Aug 07 '15 at 07:48
  • [UIImage imageNamed:images] should work fine as long as you have an image asset by that name.... post the code snippet and a screenshot of your Images.xcasset – Swapnil Luktuke Aug 07 '15 at 07:49
  • Image assets work same as any other pic in the directory. [UIImage imageNamed:@"images.png"] should work. – Samraan Khaan Aug 07 '15 at 07:57
  • @lukya But it states in this answer http://stackoverflow.com/questions/19587139/load-app-icon-from-xcassets that loading it directly doesn't work, and I also tried it. It really didn't work. You can see he also states that he tried [UIImage imageNamed:@"AppIcon"]. It didn't work. – JLT Aug 07 '15 at 08:04
  • 1
    AppIcon stuff can be tricky... try the same for another image and it should work... – Swapnil Luktuke Aug 07 '15 at 08:34

2 Answers2

1

As you said at last that you are using AppIcon as a test. Please don't AppIcon it is made for internal use. try to create you own imageSet and use that. It should work.

0

Two things :

  1. As said Ankit, do not use App Icon, use your own set
  2. do not use a file suffix. Just reference [UIImage imageName:@"MyImage"] (not [UIImage imageName:@"MyImage.png"])
Henry_821018
  • 191
  • 1
  • 6