I am developing an app, and I want it can be used on iPhone 4 and 5, as the iPhone 5 had changed its size to 4-inch, so I want my app can be supported 4-inch, but in Xcode4.3 there is no autolayout, because of this , I wonder if there is anyway to get the display screen size and change it to 4-inch, thank you very much!
Asked
Active
Viewed 48 times
0
-
make your app from code, not from IB – Magyar Miklós Oct 20 '13 at 01:07
-
1Why are you using xcode 4.3? – AdamG Oct 20 '13 at 03:08
-
upgrade to 4.6 or higher & use this:http://stackoverflow.com/a/18132334/2535467. – CaptJak Oct 20 '13 at 03:19
-
Even without auto layout, there still is autoresize. Autoresize is what was used before auto layout and does management of sizes and placement of views, though it's nowhere near as sophisticated as auto layout. Depending on your app it would probably work. I would, however, recommend updating Xcode if you can. – BergQuester Oct 20 '13 at 05:56
-
Finally, i update the Xcode to 4.5, and it is easy to solve this – laiqn Oct 22 '13 at 10:12
1 Answers
1
You can get the screen size by using this code:
CGRect screenBounds = [[UIScreen mainScreen] bounds];
UIViewController *ViewController;
[self loadall];
if (screenBounds.size.height == 568) {
NSLog(@"User is using an iPhone 5+");
BOOL isUsingiPhone5 = YES;
}
else{
NSLog(@"User is using an iPhone 4s-");
BOOL isUsingiPhone5 = NO;
}
then you could move things accordingly, with CGRect
heres an example of moving an ad banner view as a result of the screen size:
-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
CGRect bannerFrame = banner.frame;
CGRect screenBounds = [[UIScreen mainScreen] bounds];
UIViewController *ViewController;
if (screenBounds.size.height == 568) {
//iPhone5+
bannerFrame.origin.x = 0;
bannerFrame.origin.y = 518;
banner.frame = bannerFrame;
}
else{
//iPhone4s-
}
NSLog(@"Showing ad, internet connection found.");
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
}
else{
[banner setAlpha:0];
}
Make sure to use ViewController
as the UIViewController
variable, even if your default view controller is named something like RootViewController.
Hope this helps. Feel free to comment if you have any questions!

Jojodmo
- 23,357
- 13
- 65
- 107