0

I have code project written on xcode 5.1. I have set the frames of all the controls which is working fine with iPhone 5 and later. But when I run the same project on iPhone 4s, the frames I have adjusted is not fitting to the screen of iPhone 4s. Please could someone help me with the easy solution of how to adjust the frame of all controls. Will I need to manually change the frame of all the controls?

Funny
  • 566
  • 5
  • 16

3 Answers3

0

You can use multiple xib/storyboard one for iphone5 screen size and another one for iphone4 screen size

and then make changes in appDelegate like this

// if use story board

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
     UIStoryboard *storyBord;
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
   {
         if(self.window.frame.size.height == 568)
             storyBord = [UIStoryboard storyboardWithName:@"Main_iPhone5" bundle:[NSBundle mainBundle]];
        else
             storyBord = [UIStoryboard storyboardWithName:@"Main_iPhone4" bundle:[NSBundle mainBundle]];
   }
   self.window.rootViewController = [storyBord instantiateInitialViewController];
   [self.window makeKeyAndVisible];

return YES;
}

// if you are using .xib files then each view controller.m file you have to init like this

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        if([UIScreen mainScreen].bounds.size.height == 568)
            self = [super initWithNibName:@"FeedActivity_iPhone5" bundle:[NSBundle mainBundle]];
        else
            self = [super initWithNibName:@"FeedActivity_iPhone4" bundle:[NSBundle mainBundle]];
    }
}
return self;
}

You can also go with Use auto layout but it seems this goes easy for you

Anand Suthar
  • 3,678
  • 2
  • 30
  • 52
0

enter image description here

mainly it depends on your requirement, but still setting this autoresizing mask to your element will help you.

Autoresizing masks programmatically vs Interface Builder / xib / nib

Community
  • 1
  • 1
Mayank Jain
  • 5,663
  • 7
  • 32
  • 65
0

You can use autolayout. To do it so, you first check if the storyboard has autolayout checked

autolayout

Then, you need add the constraints

constrains

I recommend you to check this video:

https://www.youtube.com/watch?v=r1sc7NI6-wo

Adriano Spadoni
  • 4,540
  • 1
  • 25
  • 25