user3218052
user3218052

Reputation: 11

make an app which is compatible for both iphone and ipad

I am using both device for make my application.my application is perfectly run in iPad but when i select device as iPhone 4inch there is an error occur in interface.below is picture. you can see black color in top and bottom where did it came from?

enter image description here

and here is my code:

in app delegate:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
    if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
    {
        NSLog(@"Ipad ");
        [application setStatusBarStyle:UIStatusBarStyleLightContent];

        self.window.clipsToBounds =YES;

        self.window.frame =  CGRectMake(0,-20,self.window.frame.size.width,self.window.frame.size.height+20);
    }
    if
     (IS_IPHONE_5)
    {

        NSLog(@"Iphone %f ",[[UIScreen mainScreen] bounds].size.height);
        if ([[UIScreen mainScreen] bounds].size.height == 568) {

            [application setStatusBarStyle:UIStatusBarStyleLightContent];

            self.window.clipsToBounds =YES;

            self.window.frame =  CGRectMake(0,-20,self.window.frame.size.width,self.window.frame.size.height+20);
        }
    }

}

enter image description here

Upvotes: 0

Views: 295

Answers (3)

shankar
shankar

Reputation: 614

If you want to use compatible for both iPad and iPhone(standard, 3.5 inch, 4 inch), try this

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
    if ([UIScreen mainScreen].scale == 2.0f) {
        CGSize result = [[UIScreen mainScreen] bounds].size;
        CGFloat scale = [UIScreen mainScreen].scale;
        result = CGSizeMake(result.width * scale, result.height * scale);

        if(result.height == 960){
            NSLog(@"iPhone 4, 4s Retina Resolution");
        }
        if(result.height == 1136){
            NSLog(@"iPhone 5 Resolution");
        }
        else {
            NSLog(@"iPhone Standard Resolution");
        }
    }
    else {
    //iPad
        if ([UIScreen mainScreen].scale == 2.0f) {
            NSLog(@"iPad Retina Resolution");
        } 
        else{
            NSLog(@"iPad Standard Resolution");
        }
}

Upvotes: 1

Mani
Mani

Reputation: 17595

If you want to support app for iPhone 5 screen. You should add image which enable app for iPhone 5 screen size. This should be implement from xcode 4.5+

Add this image to your project Xcode screenshot. To enable your apps to work with iPhone 5, you need to add a retina version of the launcher image. It should be named Default-568h@2x.png

Set the autoresizing mask of the center content to expand in both directions.

view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

Otherwise you can change view size by below code which will make you screen to compatible with your iPhone 5 screen.

CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
    // code for 4-inch screen
} else {
    // code for 3.5-inch screen
}

Upvotes: 2

sabeer
sabeer

Reputation: 603

Add a Default retina image for iphone 5 640*1136

Upvotes: 0

Related Questions