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?
Asked
Active
Viewed 33 times
0
-
you should use autolayout or autoresizing. – Mayank Jain Apr 15 '14 at 09:51
-
Please explain me how can I use autolayout or autoresizing – Funny Apr 15 '14 at 09:53
3 Answers
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
-
-
@AnandK is it good idea to create multiple xib. why are you not suggesting autolayout or autoresizing? – Mayank Jain Apr 15 '14 at 10:04
-
0
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
Then, you need add the constraints
I recommend you to check this video:

Adriano Spadoni
- 4,540
- 1
- 25
- 25