Search code examples
iphoneiosobjective-cuiviewiphone-5

How to convert existing height of UIView for iphone 5


Hi I have developed app for iPhone4 now I want to convert the app into iPhone5, I have a UIView named settingsView it is popped up by click of a UIButton. I wanted to know how to adjust the height of the settingsView for iPhone5 .

 -(IBAction)settingsButtonChanged:(UIButton *)sender
{
    UIImageView *settingsImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"settingsViewImage.png"]];
    settingsImage.frame = CGRectMake(25.0, 40.0, 280.0, 370.0);


    settingsView.frame = CGRectMake(0.0, 20.0, 280.0, 370.0);
    settingsView.backgroundColor = [UIColor clearColor];
    [settingsView addSubview:settingsImage];

}

Solution

  • Maybe, you would like to use two storyboards, one for iPhones 3.5" and the other for iPhones 4". By putting this code on your app delegate, you'll be able to have those storyboards working:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    
        if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
            if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568.0){
                //move to your iphone5 storyboard
                UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iphoneFiveStoryboard" bundle:[NSBundle mainBundle]];
                UIViewController *vc =[storyboard instantiateInitialViewController];
    
                self.window.rootViewController = vc;
                [self.window makeKeyAndVisible];
            }
            else{
                //move to your iphone4s storyboard
                UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
                UIViewController *vc =[storyboard instantiateInitialViewController];
    
                self.window.rootViewController = vc;
                [self.window makeKeyAndVisible];
            }}
        // Override point for customization after application launch.
        return YES;
    }
    

    Now you only need to go to: File -> New... -> File -> User Interface -> Storyboard

    And name the storyboard "iphoneFiveStoryboard"...

    Now you can remake all the storyboard with 4" views!

    Hope you understood, I tried to explain the best I could...