Reputation: 109
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];
}
Upvotes: 2
Views: 613
Reputation: 2433
You can try this-
-(IBAction)settingsButtonChanged:(UIButton *)sender
{
UIImageView *settingsImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"settingsViewImage.png"]];
CGRect screenBounds = [[UIScreen mainScreen] bounds];
int height = 0;
if (screenBounds.size.height == 568) {
// Height for iPhone 5 screen
height = 370+ 88; // it may be your desired height
} else {
// Height for iPhone 4 screen
height = 370;
}
settingsImage.frame = CGRectMake(25.0, 40.0, 280.0, height);
settingsView.frame = CGRectMake(0.0, 20.0, 280.0, height);
settingsView.backgroundColor = [UIColor clearColor];
[settingsView addSubview:settingsImage];
}
Upvotes: 0
Reputation:
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...
Upvotes: 3
Reputation: 125007
If you use the new autolayout system, you can set constraints that will automatically adjust your view's layout to take advantage of the screen size. For example, if you have several elements near the top of the view, a table in the middle, and some buttons near the bottom, you can add constraints that:
You can do the math and make the adjustments yourself, but the whole point of the autolayout system is that you don't have to bother -- let the view do it for you.
Upvotes: 4
Reputation: 975
You have to check whether the app running on iPhone 4
or iPhone 5
below code lines may help you:-
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568)
{
// code for 4-inch screen
//for eg:-
[self.view setFrame:CGRectMake(0, 0, 320, 568)];
}
Upvotes: 2
Reputation: 17902
use self.view.frame.size.height
, you may have to divide this by something to match your ratio of 320:280 that I noticed for width
-(IBAction)settingsButtonChanged:(UIButton *)sender
{
UIImageView *settingsImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"settingsViewImage.png"]];
settingsImage.frame = CGRectMake(25.0, 40.0, 280.0, self.view.frame.size.height);
settingsView.backgroundColor = [UIColor clearColor];
[settingsView addSubview:settingsImage];
}
Upvotes: 2