Search code examples
iphoneiosframeiphone-5autoresize

How to set frame size for iphone 5


I am setting my iphone app screen frames to support iphone 5 , i have set the auto resizing mask mask and also i tried by setting the frame programmatically using the following code in loadview

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        CGSize result = [[UIScreen mainScreen] bounds].size;
        if(result.height == 480)
        {
            // iPhone Classic
        }
        if(result.height > 480)
        {
            // iPhone 5
           CGRect mainFrame = CGRectMake(0, 0, 320, 568);
           self.view.frame = mainFrame;
        }
    }

but it didnt work didn't work ,

can any one tell me how do i set the frame , thanx in advance


Solution

  • Use this to check :

    #define IS_IPHONE ( [[[UIDevice currentDevice] model] isEqualToString:@"iPhone"])
    #define IS_HEIGHT_GTE_568 [[UIScreen mainScreen ] bounds].size.height >= 568.0f
    #define IS_IPHONE_5 ( IS_IPHONE && IS_HEIGHT_GTE_568 )
    #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    

    So

    if(IS_IPHONE_5)
    {
     // Iphone 5 frame
    }
    else
    {
    // iphone 4 frame
    
    }
    

    and add [email protected] in your project also.

    Hope it helps you.