Does @2x for retina work on all images, and how do i test for a retina display?
I have 3 short questions, very related:
How do i detect if the user is using a retina device?
I want to save an image inside my app in documents, if i detect that they're using a retina display phone and save the image ending in
@2x.jpg
will it work as it does with imported images, where it'll automatically go for that one instead on a retina device?If i were to reference an image which didn't exist, but a
@2x.jpg
version ex开发者_开发百科isted, would it go to that by default?
- Use
[UIScreen mainScreen].scale
, it's2.f
when it's a retina screen. - I'm not sure, but I think it'll automatically detect
@2x
-versions here too (as long as you useUIImage
to load them). - If it's a retina screen, it'll look to the
@2x
-version first, if it doesn't exist, it'll fallback to the default-version. If that version doesn't exist, it'll returnnil
. A non retina screen however, will never look to the@2x
-version.
You call it a x2.jpg
-file, however, it isn't:
- Your default file is something like
background.png
. - Then your retina file should be like
background@2x.png
. - You load the image using
UIImage *image = [UIImage imageNamed:@"background.png"];
. - In most situations you don't need to know if it's a retina screen, iOS will handle this.
精彩评论