I am having iPad specific application. I want to play same on iPhone also. My app having xib which used size class "wRegular hRegular" with many auto layout constraints. I want to covert this to wAny hAny size class. I know there are two way to achieve this either using auto layout or creating another xib file for iPhone only. I want to go with separate xib files But how to make this files in XCode 7? And how this will work?
Asked
Active
Viewed 57 times
0
-
3Possible duplicate of [Trouble with loading a separate XIB for iPad or iPhone](http://stackoverflow.com/questions/5306346/trouble-with-loading-a-separate-xib-for-ipad-or-iphone) or [http://stackoverflow.com/questions/13496218/xib-for-iphone-and-ipad](http://stackoverflow.com/questions/13496218/xib-for-iphone-and-ipad) – Ketan Parmar Aug 01 '16 at 12:21
1 Answers
0
Just create new XIB file with name whatever you want to give and load the UIViewController using following code
ViewControllerName *vc = [[ViewControllerName alloc] initWithNibName:@"" bundle:nil];
In ViewController override - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil method in which check for device is iPhone or iPad using following code
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
NSString * nibNameOrNil;
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ){
// iPad
nibNameOrNil = @“iPad_XIB_NAME”
} else {
// iPhone
}
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
}
return self;
}
this will call your XIB according to your device type.

RBN
- 482
- 4
- 13