Apart from @2x, what other tags are supported by U

2019-09-07 07:23发布

问题:

I know I can use the @2x tag to automatically load images for Retina screens. What other tags are supported?

回答1:

There are currently three supported tags:

  • @2x for Retina screens.
  • ~iPad for iPad, has to be the last tag before the extension.
  • ~iPhone for iPhone and iPod Touch, again, has to be the last.

For the splash screen there’s also the Default-568h@2x version for iPhone 5. This suggests that you can use -568h to automatically load images for iPhone 5, but that’s unfortunately not the case (rdar://12516489). You can patch the UIImage class to add the support yourself.

In the end there are five possible image variants:

  • Image.png for older devices, 480✕320
  • Image@2x.png for Retina, 960✕640
  • Image-568h@2x.png for Retina, 1136✕640, only after patching UIImage
  • Image~iPad.png for older iPads, 1024✕768
  • Image@2x~iPad.png for Retina iPad, 2048✕1536

All this is showcased in iOS Image Loader sample project on GitHub.



标签: ios uiimage