I'm using an image that will fill the full view of an iPhone. For iPhone 3GS we name it image.png for iPhone 4 we name it image#2x.png -is there an image name convention for iPhone 5 where it will automatically substitute it, or do I need to manually check which device I'm on?
I've read elsewhere that we keep on using #2x but I don't want my image stretched.
There is no specific image name conventions for iPhone 5 except for the Default-568h#2x.png image.
Your images will not be stretched when you use #2x on the iPhone 5, it is just the layout that will change.
Since there is no specific naming convention for the 4" screen (5th gen iPod touch and iPhone 5), you need to check the screen height yourself and load a different image.
if ([UIScreen mainScreen].bounds.size.height == 568) {
// 4" screen - load appropriate image
} else {
// regular screen - load standard image
}
This will work in portrait orientation.
Related
I develop application using iOS5.0, now I want to run app in iOS6.0. It's working fine using iPhone classic devices, but not working fine in iPhone5.
Because [[UIScreen mainScreen] bounds] is returning {{0, 0}, {320, 480}} in iPhone5, I wrote code using
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if (result.height == 480)
{
// iPhone Classic
}
else if (result.height == 568)
{
// iPhone 5
}
}
But screen bounds return same frame. How it will change?
Add splash screen for iPhone 5. You can see a warning if you go to Your Target -> General -> Launch Images.
For the application to run in "tall mode", you need to have a Default.png splash screen the correct height for an iPhone 5. This will instruct the application to run in tall mode, meaning you'll get the correct bounds.
Information can be found at the Apple Dev Centre. Basically, you'll need to provide a splash/launch image with a size of 640 x 1136 pixels, and a name of Default-568h#2x.png.
To specify default launch images for iPhone 5 and iPod touch (5th generation) devices, include the modifier string -568h immediately after the portion of the filename. Because these devices have Retina displays, the #2x modifier must always be included with launch images for the devices.
For example, the default launch image name for a device is Default-568h#2x.png. (If your app has the UILaunchImageFile key in its Info.plist file, replace the Default portion of the string with your custom string.).
You can easily add this image via the target settings for the project in Xcode. Simply select your project file, then select the application from the target list. Within General, you'll find settings such as Application Version number, Deployment Target etc... Further down the list you can select your launch images, and there'll be a placeholder for iPhone 5 devices.
My universal app has two storyBoards. One for iPhone and one for iPad. A lot of the code has been coded programatically and both storyBoards share the same ViewControllers. An example of how this works in view controller as follows:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ iPadInUse = YES;}
else { iPadInUse = NO;}
So, if I have a image that needs to be displayed on both devices - I write the following:
if (iPadInUse == YES) { recordViewImage = #"iPadRecordPanel#2x.png"
// x and y positions to adjusted accordingly }
else { recordViewImage = #"recordingPanel#2x.png"
// // x and y positions to adjusted accordingly}
On the simulators everything works fine for all devices (retina /non retina). The only actual device I have is an iPhone 4S (all works fine). Is this ok what I'm doing as do not actually have any non retina images loaded fro non retina devices (all images suffix with #2x.png ??
Will my app get rejected because of this ??
No, this is not ok.
On devices that do not have retinta screen more memory will be used to load the retina images.
You should always provide non retina and retina images and never load #2x images directly. iOS will load the correct image for you.
Your app will not get rejected, and everything will work fine.
But there are two issues:
On non-retina devices, App will load larger images. Which is not required there..so memory utilization will increase there without any outcome.
You don't need to write conditional code for iphone and ipad for setting images.
You can use a tilde while naming the image files:
iPhone:
image#2x~iphone.png (retina only)
image#2x.png (retina only)
image~iphone.png
image.png
iPad:
image#2x~ipad.png (retina only)
image#2x.png (retina only)
image~ipad.png
image.png
It will not display proper image when you will give it name like iPadRecordPanel#2x.png. You can give name iPadRecordPanel.png and it will take 2x image of it from bundle. You can not give suffix with #2x. it will automatically identify proper image and display it.
No your app will not be rejected but you should not do this because not providing non-retina images may decrease performance and image quality on older devices due to the required down-scale operations.
Hope it helps you.
I have an image named abc.png of size 320 by 156 which runs well on iPhone 4 and an image named as abc#2x.png of size 640 by 312 which also works fine. but when Please enlighten me on how to use the image for the iPhone 6 device?
First of all there is nothing like iPhone6 as of now, it is either iOS6 or iPhone 5.
But I guess you are talking about iPhone 5 with screen resolution 640X1136.
There is no in-built way to select image for iPhone 5.
if you have abc.png and abc#2x.png in resources , and you use a code like:
UIImage * image = [UIImage imageNamed:#"abc.png"];
it will pick abc.png for non-retina display and abc#2x.png for retina display(that includes iPhone 4S and iPhone 5).
If you want to load separate image for iPhone 5, you will need to check the screen height:
if(screenHeight == 480)
{
//iphone 3,3G,4
}
else if(screenHeight == 960)
{
//iphone 4S
}
else if(screenHeight == 1136)
{
//iphone 5
}
This way you may load different images for different iphones.
Please uprate and check the answer if it answers ur question.
The answer to your question, I'm afraid to say, is something called AutoLayout. That's the solution Apple came up with to deal with the different form factor for iOS 6 views. Only #2x images are available, but with AutoLayout, you can tell it exactly how to behave.
Here's a nice tutorial on how to use AutoLayout, I tried it and it works well:
http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2
http://www.raywenderlich.com/20897/beginning-auto-layout-part-2-of-2
what is the Image Naming Convention for iPhone 5 like #2x for retina screens.
It is just the same. The #2x just means it's a retina image.
The only difference is the 568#2x (or whatever it is) for the splash screen but Xcode renames that file for you anyway.
Just keep using #2x.png
till now they have not released any official documentation for the iPhone5 Images.
You can do like this.
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && [[UIScreen mainScreen] bounds].size.height * [UIScreen mainScreen].scale >= 1136)
{
//Write the code here for iPhone5 Image.
}
else
{
//this is for unto 4th gen iPhone
}
There is no specific naming convention for images on iPhone 5.
The Default-568h#2x will be shown on launch of an iPhone 5 or iPod Touch 5G. This will also enable the non-letterbox mode of your app. For your other f.e. background images you have to design flexible if you want to cover both screen resolutions. When you building an iPhone 4s App assure that f.e. a background image can be strechted up to the iPhone 5 size.
it is just the same. The #2x just means it's a retina image.
The only difference is the 568#2x (or whatever it is) for the splash
screen but Xcode renames that file for you anyway.
Just keep using #2x.png
I must add, that if you look at the simulator the pictures maybe stretched! You could fix this by checking the box (if u use storyboard) "auto layout" I have some problems too maybe this is a bug which will be fixed I hope...
and on storyboard or .xib u can change the size of the controller like here:
I have been looking everywhere for this but with no luck.
How do I prepare my cocos2d based game for bigger 4 inch display of the iPhone 5?
My app is working but i want to enhance it for the bigger 4 inch display.
Cocos2d uses its own suffixes for retina display images. For retina display of the iPhone 4 and 4S it is image-hd.png. Is there a suffix for iPhone 5? How do I accomplish this?
Cheers.
There is no extra file suffix for iPhone 5, after all it's only 176 pixels (88 points) wider. It's treated like a regular Retina phone, hence cocos2d will load the -hd files.
The rest is just about positioning your images depending on the device. The simplest way is to just treat the 44 points on either side as a "dead zone" where no user input can occur and where there's no guarantee the user can see game objects.
Update:
cocos2d 2.1 added the -widehd suffix. It was said that 2.1 final release will have the suffix renamed to -iphone5hd.
In light of future screen sizes I sould personally set and use a -568hd suffix because other phones beside iPhone 5 may have the same resolution. Naming the suffix after a specific iPhone model is a tad short-sighted to say the least.
Add it to AppDelegate:
[CCFileUtils setiPadRetinaDisplaySuffix:#"your suffix"];
[CCFileUtils setiPadSuffix:#"your suffix"];
[CCFileUtils setiPhoneFourInchDisplaySuffix:#"your suffix"];
[CCFileUtils setiPhoneRetinaDisplaySuffix:#"your suffix"];
Not sure why everyone is saying there isn't.
The suffix is -568h for iPhone5/iPod Touch 5th (so the 4 inch retina displays).
The total list:
-hd (iPhone 4/4S, iPod Touch 4th)
-568h (iPhone 5, iPod Touch 5th)
-ipad (iPad 1st/2nd)
-ipadhd (iPad 3rd/4th)
Add this to AppDelegate with your chosen suffix:
if((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) && ([[UIScreen mainScreen] bounds].size.height == 568)) {
[sharedFileUtils setiPhoneRetinaDisplaySuffix: #"-your suffix"];
}
It took me awhile to figure this out, since I'm new to cocos2d. So I thought a recap might be helpful for those like me. In cocos2d 2.1, all you have to do is creating graphics for the target screen sizes and follow cocos suffix naming convention. Note that cocos's suffix convention is not the same as iOS's.
In my case, I have a background image that occupies the full screen. So, I made...
background.png at 480x320 for iPhone
background-hd.png at 960x640 for iPhone retina (3.5")
background-iphone5hd.png for iPhone5 retina (4")
And use the following code to load the image into CCSprite. Cocos will figure out which image to use for you.
CCSprite *background = [CCSprite spriteWithFile:#"background.png"];
background.position = ccp(background.textureRect.size.width/2,
background.textureRect.size.height/2);
[self addChild:background];
For an element like a character that doesn't occupy the full screen, cocos2d will pickup character-hd.png automatically in iPhone5. There is no need to create character-iphone5hd.png version.
You can read more about this in version 2.1 release note at
https://github.com/cocos2d/cocos2d-iphone/wiki/cocos2d-v2.1-release-notes
This is how i did it for cocos2d v2.1-beta4.
In CCFileUtils.h i added:
- (void)setIphone5HDSuffix:(NSString *)suffix;
In CCFileUtils.m:
- (void)setIphone5HDSuffix:(NSString *)suffix
{
[_suffixesDict setObject:suffix forKey:kCCFileUtilsiPhone5HD];
}
In AppDelegate.m:
[sharedFileUtils setIphone5HDSuffix:#"your_suffix"];
And that's enough!
Did you follow the following post, adding the default image for it, named Default-568h#2x.png with a resolution of 1136x640?
How to develop or migrate apps for iPhone 5 screen resolution?
If it does not work, I found this post on cocos2d forum, containing a lot of infos:
iPhone 5 1136 x 640 screen resolution: http://www.cocos2d-iphone.org/forum/topic/39491
Now cocos2d support iPhone wide screen also.
-wide.png for iphone 5
-widehd.png for iPhone 5 HD
I was just playing around with suffixes in Cocos2D 2.1-rc1 and was able to get it to automatically load a iPhone5 file with the "-iphone5hd" suffix, not changing anything in AppDelegate in the sharedFileUtil section of code. Hope that helps, also.