Andrew
Andrew

Reputation: 16051

Does @2x for retina work on all images, and how do i test for a retina display?

I have 3 short questions, very related:

  1. How do i detect if the user is using a retina device?

  2. 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?

  3. If i were to reference an image which didn't exist, but a @2x.jpg version existed, would it go to that by default?

Upvotes: 0

Views: 1285

Answers (1)

cutsoy
cutsoy

Reputation: 10251

  1. Use [UIScreen mainScreen].scale, it's 2.f when it's a retina screen.
  2. I'm not sure, but I think it'll automatically detect @2x-versions here too (as long as you use UIImage to load them).
  3. 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 return nil. 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 [email protected].
  • 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.

Upvotes: 5

Related Questions