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.
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
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With