Reputation: 1089
NSString *devicetype;
if((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)){
devicetype = @"ipad";
}else{
devicetype = @"iphone";
}
I have two images
BACKGROUND_IPAD.PNG
AND
BACKGROUND_IPHONE.PNG
Now I want to use this string like
BackGround = [CCSprite spriteWithFile:[NSString StringWithFormat:@"background_%@.png",DEVICETYPE]];
Is this possible? If not, then is there a better way?
Upvotes: 0
Views: 107
Reputation: 21221
Yes you an use it, but insread of that you can change the name of the image to the following
Image~ipad.png
Image~iphone.png
Now when you load the image
//on the iPhone and iPad use the same image name
//image named will select the image automatically
UIImage *image = [UIImage imageNamed:"Image"];
It will automatically select the image basing on your current device
Upvotes: 4