Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone 4" screen with xcassets not pulling correct image

I am trying to implement using Images.xcassets into a project I am working on. From what I understand I can just put all the different sized images for different devices in there and then call [UIImage imageNamed:@"name_of_image_set"] and it will return the correct image for the device I am working on.

It seems to be pulling the correct image for everything except the iPhone 5/5s/5c with the 4" screen. For that screen size it gives me the image for the @2x iPhone with the 3.5" screen.

Image of config in Images.xcassets

Here is the json that is included in the folder with the images.

{
  "images" : [
    {
      "idiom" : "iphone",
      "scale" : "1x",
      "filename" : "bg.png"
    },
    {
      "idiom" : "iphone",
      "scale" : "2x",
      "filename" : "[email protected]"
    },
    {
      "idiom" : "iphone",
      "filename" : "[email protected]",
      "subtype" : "retina4",
      "scale" : "2x"
    },
    {
      "idiom" : "ipad",
      "scale" : "1x",
      "filename" : "bg~ipad.png"
    },
    {
      "idiom" : "ipad",
      "scale" : "2x",
      "filename" : "bg@2x~ipad.png"
    }
  ],
  "info" : {
    "version" : 1,
    "author" : "xcode"
  }
}

Everything seems to be in order, am I just misunderstanding how xcassets are supposed to work?

Thanks

Joel Bell

like image 772
Joel Bell Avatar asked Sep 27 '13 17:09

Joel Bell


1 Answers

I came across this problem and the issue seems to be targeting iOS versions lower than 7.0 The solution for me was to create a separate image set with a single @2x image on it and instantiate the correct one programmatically by detecting the iPhone screen size in code like done here

Related: Why isn't my Asset Catalog returning R4 images?

like image 145
Alejandro Benito-Santos Avatar answered Nov 09 '22 12:11

Alejandro Benito-Santos