I'm developing the app to work both on iphone4 and iPhone 5. I'm using the following code to get the screen size
CGRect screenBounds = [[UIScreen mainScreen] bounds];
am using the iPhone 5 simulator but it showing the screen size of iPhone 4.
On the simulator make sure you have set to iPhone (Retina 4-inch).
You can do this by going simulator menu at the top go to Hardware>>Device>>iPhone (Retina 4-inch) that will change the phone simulator to the iPhone 5 version.
If this is set then you may need to add a launch image for the iPhone 5. Default-568h#2x.png if this is missing it will not launch in iPhone (Retina 4-inch).
I have also answer another question here that may help.
When running the simulator, go to Hardware -> Device and make sure that iPhone (Retina 4-inch) is selected.
In fact
[[UIScreen mainScreen] bounds].size.height
returns 568 for iPhone 5. Make sure, you selected "iPhone 4 - (4 inch)" as Device in the Simulator (it's there since Xcode 4.5). There should also be an Default-568h#2x.png file in your project if you created your project using the Xcode assistent.
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.
I encountered with a strange problem. I develop an application which is targeting iPhone device family with Retina 3.5 and 4. All the time I used iPhone 5 simulator to test all the UI and functionality and everything was good but know I have to test push notifications. I have iPad 4 (model MD522ZP/A) as an iOS 6 device. When I run my app on it all the UI layout became wrong. The most weird problem is when I tried to check display resolution with this code:
NSLog(#"RESOLUTION = %#", NSStringFromCGSize([UIScreen mainScreen].bounds.size));
I got this : RESOLUTION = {320, 480}. But it is iPhone 3 resolution! Why iPad didn't use Retina 3.5/4 resolution ? And how can I fix it? I don't want to create separate xibs only for iPad testing but I want to test my app on it so that all the UI elements will fit on screen.
Hope for the help.
It's not wrong. It is doing exactly the right thing. All references to sizes are in points, not pixels. When you get the bounds, it will be 320x480 on all 3.5" screens whether they are retina or not. Try it on any 3.5" retina device. You will get the same log output.
The iPad does not emulate a 4" device when running an iPhone-only app. It will always be a 3.5" iPhone compatible mode.
So seeing 320x480 is the correct size to expect.
Think of it this way. A retina iPad will show an iPhone-only app like it is running on a 3.5" retina iPhone. A non-retina iPad will show an iPhone-only app like it is running on a 3.5" non-retina iPhone.
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 want to update my app so that can be deployed on iPhone5.
Xcode(4.5) has a Default-568h#2x.png which is a black image(640X1136).
In iPhone5's simulator, it still loads the old Default#2x.png. I wanted to know whether it will be same on the actual device ?
Thanx !!!
Switch to the "iPhone (Retina 4-inch)" device from the Hardware menu in the simulator and you should see the iPhone 5 default image on launch.
Happens to me when I launch iPhone 4" simulator with iOS 5.1. When changed to iOS 6, launch image is OK.
I built and ran an iOS 4.3 app in Simulator. It initially brings up an iPhone 4 shell. Although all real iPhone 4s have retina display, this simulated iPhone 4 only has a resolution of 320x480.
I look in Hardware > Device. There's a checkmark next to the normal iPhone. So I'm using an iPhone 4 case but displaying normal iPhone resolution? I'm already confused!
iPad
✔ iPhone
iPhone (Retina)
I then switch over to iPhone (Retina). Strangely, it opens iPad with the same 320x480 resolution. Both the shell and the resolution are wrong here!
How am I supposed to turn Retina on and off and show it in the right shell?
iPhone (Retina) is the correct device to be choosing, but I'm not sure why Apple decided to use the iPad shell for that one. To enter 640x960 mode, go to Window > Scale and set it to 100%.
The iOS Simulator does indeed scale. I have no real reason to present on why it would choose the iPad shell, but the purpose of the scaling is to make sure it fits on your screen and stays (relatively) close to handset sizes. Be sure to check Window -> Scale and set it to whatever you find appropriate.