Image resources for iOS

前端 未结 5 621
天命终不由人
天命终不由人 2020-12-05 00:29

I\'m probably missing something obvious here, yet I\'ve been unable to solve the following problem:

I have a project with image resources for both normal and retina

相关标签:
5条回答
  • 2020-12-05 00:51

    When you are creating images for your app, let's say you're creating an image called example.

    You should save the following:

    • example~iphone.png -> this is for non retina iPhone
    • example~iphone@2x.png -> this is for retina iPhone
    • example~ipad.png -> this is for non retina iPad
    • example~ipad@2x.png -> this is for retina iPad

    So, it doesn't matter from where you call it, you just call it this way, assuming myImageView is a UIImageView object:

    [myImageView setImage:[UIImage imageNamed:@"example"]];
    

    Apple strongly recommends you to use png images. Also, the OS takes care of finding the correct image for the desired device. You don't need to worry about finding the path and all that stuff. +(UIImage*)imageNamed:(NSString*)name looks for the correct image in your resources bundle - and by the way, to return the bundle with your resources just call [NSBundle mainBundle];

    0 讨论(0)
  • 2020-12-05 00:53

    -> build settings -> COMBINE_HIDPI_IMAGES to NO

    this is the only solution that works and no other change is necessary

    0 讨论(0)
  • 2020-12-05 01:04

    If you are working with bundles than go to

    -> build settings -> COMBINE_HIDPI_IMAGES to NO,

    and you just need to clean and build!

    0 讨论(0)
  • 2020-12-05 01:12

    Have you tried to simply load the image using:

    UIImage * someImage = [UIImage imageNamed: @"someimage"];
    

    (assuming your have an image named 'someimage' in you project, for example someimage.png)

    The code will automatically pick retina/non-retina versions depending on the platform.

    If the problem is that the TIFF are created, check:

    XCode Combine high-resolution artwork

    In latest version of XCode, go to the Editor menu, then select "validate settings", which should remove that artwork combination.

    0 讨论(0)
  • 2020-12-05 01:14

    Multipage TIFFs are only for OSX; they don't work on iOS.

    So you need to stop trying to access resources that are, by their very nature, inaccessible, and do things the right way!

    You need to open the project that generates the external resources bundle, select the target, go to Build Settings and then the Deployment sub-heading, and set "Combine High Resolution Artwork" to No. Then recompile the external resources bundle.

    In your main project you should now be able to read in the PNGs in the normal manner.

    0 讨论(0)
提交回复
热议问题