Possible duplicate:
How to make xib compatible with both iphone 5 and iphone 4 devices
Can I use two xibs with one viewcontroller - re: porting to iPhone 5
I have developed an iPhone app which now I'm trying to update giving it iPad and iPhone5 support.
I now there are lots of posts talking about how to handle this but none of them are working for me. 3.5'' iPhones and iPads load the xib they need but 4'' iPhone doesn't (although in simulator works fine), so here is how I handle it:
First of all I create three different xib files for each viewController (ViewController.xib, ViewController~ipad.xib and ViewController-568.xib). In the 4'' xib one I set the size of the view as "Retina 4 Full Screen".
Then I have used this to load the appropiate xib. It also may be relevant to say that in the AppDelegate I set the didFinishLaunchingWithOptions like this:
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
NSString *nibName = [UIViewController nibNamedForDevice:#"ViewController"];
self.viewController = [[BPViewController alloc] initWithNibName:nibName bundle:nil];
UINavigationController *navCont = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navCont;
[self.window makeKeyAndVisible];
self.viewController.navigationController.navigationBar.barStyle = UIBarStyleBlack;
return YES;
}
As I said it works like a charm in the simulator but in real device only iPad's and 3.5'' xib are load properly. The iPhone5 still is showing the up and down black bar...
You appear to be using the wrong suffix on your nibs/assets, use -568h#2x instead of -568h.
Alternatively i always switch various iOS assets / positions in code using:
if([ [ UIScreen mainScreen ] bounds ].size.height == 568 )
{
//iPhone 5.0 specific code
}
else
{
//None iphone 5 code
}
Its also worth noting at this stage that using more nib files to do this will result in a bigger .IPA. So its worth reading up on how autolayout works and going for that approach to keep executable size down.
Related
my project runs without storyboards, so im loading my view inside AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;
self.window.rootViewController = [[SYLoginController alloc] init];
[self.window makeKeyAndVisible];
return YES;
}
It used to work on iPhone 6 sim 9.3 but now, on all simulators it only shows a black screen. But on my iPhone 6 Device it works. Whereas on another iPhone 6 it also shows a black screen. Those two iPhones are literally the same 16gb iPhone 6 bought at nearly the same time.
In SYLoginControllers viewDiDLoad I'm logging the text of one of the buttons. Only on my device it prints the text, on all simulators and the other iPhone it prints (null), so i assume that the xib is not properly loaded.
SYLoginController is a UIViewController, and the related xib holds a UIView with its FilesOwner set to SYLoginController. I really can't see why it only works on this particular device. Also i tried [[SYTabBarController alloc] initWithNibName:#"SYLoginController" bundle:nil], this also does not work...
Did you tried to wrap it arround a Navigation Controller?
SYLoginController *syVC = [[SYLoginController alloc]initWithNibName:#"SYLoginController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] syVC];
self.window.rootViewController = nav;
Also check again if Custom Class is set to SYLoginController in the XIB-File. And the View is connected to the Files Owner.
I am unable to set a specific Main interface for iPad, even though my app is universal. Xcode used to have separate tabs for the Deployment Info on iPhone and iPad but now they are they same. However my game is radically different on iPhone and iPad and I need to set separate storyboards for each interface.
Someone please help if you know the solution.
you could set the value in the Deployment Info -> Main Interface to an empty string and implement a custom logic in your AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UIStoryboard *initialStoryboard;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
initialStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
} else {
initialStoryboard = [UIStoryboard storyboardWithName:#"Main_iPad" bundle:nil];
}
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = [initialStoryboard instantiateInitialViewController];
[self.window makeKeyAndVisible];
return YES;
}
You need to use size classes for this. To select the correct size class, open your storyboard file, then click on this icon towards the bottom of the screen.
Clicking wAny hAny will allow you to change the size class type and set specific constraints for the different device types. You can read more information about size classes here
This question already has answers here:
IOS 8 image scaling and auto layout
(3 answers)
Closed 7 years ago.
I'm current running the iPhone 6 simulator in my project.
I know with different iPhones you need different resolution settings.
If I want to develop for the iPhone 4, 5, 6 and 6+. In my situation, what should be the sizes for 4, 5 and 6+. I think I don't need to change 6 because I'm using it as my base.
(If you could, please add iPad to list)
If someone could in direct me to how iOS automatically selects the right image resolution according to what device they have.
Any questions just comment!
I did this in Objective-C a while ago, so forgive me if it's different for Swift.
You have to make a different .storyboard file for each image resolution, and then in your AppDelegate.m you add a some code like:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *iPhone4storyBoard = [UIStoryboard storyboardWithName:#"storyboard4" bundle:[NSBundle mainBundle]];
// Device is an iPhone 5 or 5S
UIStoryboard *iPhone5storyBoard = [UIStoryboard storyboardWithName:#"storyboard5" bundle:[NSBundle mainBundle]];
// And so on...
if ([UIScreen mainScreen].bounds.size.height == 568.0) {
self.window.rootViewController = [iPhone5storyBoard instantiateInitialViewController];
} else if (/* test for other devices here */){
self.window.rootViewController = [iPhone6storyBoard instantiateInitialViewController];
}
[self.window makeKeyAndVisible];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
return YES:
}
Which checks for device resolution, and applies the relevant storyboard.
Also, a suggestion for resizing images: Use Prepo.
Prepo automatically resizes app icons and splash screens to the desired values.
I want to optimize my app for iPhone 6 and iPhone 6+
But I have a launch screen size problem.
I created a simple project, and AppDelegate's code is:
#import "AppDelegate.h"
#import "ViewControllerOne.h" //xib screen size is 4 inch.
#import "ViewControllerTwo.h" // xib screen size is 4.7 inch.
#import "ViewControllerThree.h" // xib screen size is 5.5 inch.
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
if ([UIScreen mainScreen].bounds.size.height == 568.0) {//4 inch
ViewControllerOne *first = [[ViewControllerOne alloc]init];
UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:first];
self.window.rootViewController = navigation;
}
else if ([UIScreen mainScreen].bounds.size.height == 667.0){//4.7inch
ViewControllerTwo * second = [[ViewControllerTwo alloc]init];
UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:second];
self.window.rootViewController = navigation;
}
else if ([UIScreen mainScreen].bounds.size.height == 736.0){//5.5inch
ViewControllerThree *third = [[ViewControllerThree alloc]init];
UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:third];
self.window.rootViewController = navigation;
}
}
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
#end
When I run iPhone 6 or iPhone 6+ simulator, it always appears 4inch screen when I run this project.(I included three launch image(Default-667h#2x.png, Default-736#3x.png, Default-568#2x.png) also.
What I have to do to resolve this problem.
I checked others question that similar to mine, and used their code, but all of those not works. That is maybe my technical skills relatively row.
Once you specify the images in Assets Catalog you will see the right images
Go to YourAppTarget> General> App Icons and Launch Images> Launch Image Source > Use asset Catalog
and then drag the appropriate size for each device.
In addition to adding images you can also add a Launch Screen File. This is a .XIB file that allows you to specify constraints in addition of launch images. It only works on iOS8. To support iPhone 6 and 6+, we only add this file and specify constraints:
To set the Launch Screen File add it to your project:
File > New > User Interface > Launch Screen
Then go to: YourAppTarget > General > App Icons and Launch Image s> Launch Screen File > Set your newly created image
You will still need launch images for Retina 4" and 3.5", if you are supporting iOS 7.
I have a pretty general question - but I can't find a straight answer anywhere! If someone knows, please enlighten me!
I wanted to know the plan for submitting to the App Store with the new iPhone 5 dimensions. I assume that we will all need to make new graphics and separate views for all our apps if we don't want them letter boxed on the new device? So my question is, am I going to just make a new view controller that targets just this device? If so - what do I put into this code to make that happen? (as you see I've done it with the iPad view)
AppDelegate.mm
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil];
} else {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
Looking forward to finding out! Thanks!
Sean
You don't have to redo everything. That would be crazy. You just have to get the size of the screen or the main window instead of hardcoding a 480 point height. And set the autoresizing mask to have flexible height.
I have an app that was already in the app store and I wanted to update it for the new screen resolution. The simple answer is that I added a blank screenshot into the Retina 4-inch launch image. Once this was done, the app resized itself. My app is all table and web view with text and photo entry, so it resized beautifully.
I did try several things before discovering this, but I removed all other changes once I discovered that the Launch Image was the reason my app wasn't loading full screen.