iphone to ipad xib file change - iphone

I have the two xib files 1.main 2.language translator this is a iphone app.
I want to change UNIVERSAL APP. i upgrade the universal application. now automatically created mainwindow-ipad.xib.
i run this app in xcode 3.2 version but it display left corner only .
how can i change this app to universal ... its big headache to me.. anyone help me
Thanks in advance,
Suresh.m

Check whether app is on iPhone or on iPad and accordingly load the nibs, I mean u have to keep the Ipad versions of ur interface builder files and load them according to the target device
if([[UIDevice currentDevice]interfaceIdiom]== UIUserInterfaceIdiomPad)
{
//Load ur ipad nib file
}
else
{
//Load ur iphone nib file
}

I usually create a new universal project, and then "move" my code into the template provided. I find that much easier then trying to flip all the other knobs.
I found iphone_bharat's example interesting, but it has a small type so I had to fix it and clean it up a little bit.
+ (bool)iPad
{
// Can use UI_USER_INTERFACE_IDIOM() for iOS less than 3.2
if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad )
return YES;
else
return NO;
}

Related

Converting an iphone application into an iPad , iOS?

I currently have an iOS iPhone application.
What i want to do , is make it universal so that i can target the iPad too.
What i did , was go to the target and change the iOS application target , from iPhone to universal.
Now when i run the application on my iPad , it automatically resizes all the views for the iPad.
However there are some views , with background pictures that dont look so good , cause i need to use higher resolution pictures or in general i should change some things in the iPad version.
Where are the iPad .nib files??? I mean , i only see the iPhone ones. When i run it on my iphone , these files are used. When i run it on my iPad everything is resized correctly , but where the hell are these .nib files?
The tutorials (pretty old) that i read , suggested that when you target the iPad too , new .nib files should be created exact copies for the ipad. Why i dont see these files?
You can have iOS automatically load the right xib based on the extension, akin to how Retina graphics work. If your xib is named Awesome, and you want to convert it into having an iPhone and an iPad version (instead of being shared, rename it such that:
iPhone version:
Awesome~iphone
iPad version:
Awesome~ipad
Then, when you tell iOS to load Awesome, it'll pick which one to load based on the current platform automagically. No need for if statements in your code! You can still if you want, but it's not required.
Note: You might need to perform a clean after the rename! Sometimes some files stick around in the build when renamed.
You will just need to make new .xib files and set them to the same class and you can init that viewController with a condition:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
yourVC = [[YourViewController alloc] initWithNibName:"YourViewController_ipad" andBundle:nil];
}
else
{
yourVC = [[YourViewController alloc] initWithNibName:"YourViewController" andBundle:nil];
}
Whenever possible you should try to use the same .xib but in a lot of cases it isn't possible to do that and look good so you just make a second. Xcode won't do it automatically for you.
Let's say that you have a class. We'll call it Two.
Here are the current files that make up the Two class.
Two.h
Two.m
Two.xib
Two.xib contains a UIView sized for the iPhone. In order to make a view sized for the iPad, you should create a new XIB file (name it Two_iPad.xib), connect the XIB to Two, resize the UIView in Two_iPad.xib for the iPad, and design accordingly.
When you are creating a new instance of Two, do the following.
Two *two;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
//they are using an iPad
two = [[Two alloc] initWithNibName:#"Two_iPad" bundle:nil];
} else {
//they are using an iPhone/iPod Touch
two = [[Two alloc] initWithNibName:#"Two" bundle:nil];
}
You are creating a new instance of Two; however, you are checking which device the user has, and using the corresponding XIB file.

iOS - Converting iPhone Build to iPad

I have a application that I built that was to be build as an iPhone-only application.
Now, I am told that the application has to be made universal now. I will have to make it iPad compatible too (in portrait-only mode). I have been looking for my options right now as the XIBs in this project are heavily loaded with objects so programatically assigning co-ordinates will be a pain.
I am looking for the best, and the quickest approach I should take to make this iPhone app into iPad-compatible app as well.
PS: There is no mainwindow.xib file as the application was built with XCode 4.3 which doesn't create the MainWindow.xib file.
Thank you in advance.
EDIT: I have made duplicate XIBs for iPad for all the XIBs. Now, I am trying to use the naming convention which tells me to change the filename suffix to MyiPadXIB~ipad.xib and when the app is run on iPad, it will automatically take that XIB. This doesn't seem to be happening.
When I open the application in iPad, only a small window appears (the window that appears when iPhone-only app is run on an iPad).
Any solution to this?
I followed a very easy approach where I would just create duplicate XIBs of all the XIBs by doing Build settings > target (iPhone)> right click and choose duplicate.
I would then change the name of the duplicate xibs in this format: "iPhone XIB name"~ipad.xib.
The system would then automatically pick up the XIB according to the device used.
From what I know (there may be a quicker/better approach that i dont know of)
You would create seperate xib files for the ipad
when you init your view controller you check to see what device you are on like so
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.serverSettingsViewController = [[ServerSettingsViewController alloc] initWithNibName:#"ServerSettingsViewController_iPhone" bundle:nil];
self.motionJpegViewController = [[MotionJpegViewController alloc] initWithNibName:#"MotionJpegViewController_iPhone" bundle:nil];
} else {
self.serverSettingsViewController = [[ServerSettingsViewController alloc] initWithNibName:#"ServerSettingsViewController_iPad" bundle:nil];
self.motionJpegViewController = [[MotionJpegViewController alloc] initWithNibName:#"MotionJpegViewController_iPad" bundle:nil];
}
And load you iphone or ipad xib file (FYI make sure the xib views are large enough for the ipad)

Creating universal app for Xcode 4.3?

I am little bit confused about creating universal application for iOS devices using Xcode 4.3 , later versions (Xcode 4) have separate folder classes for this, but how will we make this using newest version of Xcode?
Thanks in advance
I don't think this has changed in Xcode 4.3 compared to previous versions of Xcode 4.* , but though you have a doubt refer to my answer below.
If you want to create a new project as Universal App then select Universal in Device Family in below image:
Or if you are trying to convert an existing iPhone or iPad app to Universal app then select Devices as Universal from Target Settings- > Summary Tab, set Devices to Universal:
Hope this helps you.
EDIT:
Let us suppose View Controller name is YourViewController
Let us suppose name of iPad XIB is YourViewController-iPad.xib and iPhone xib name is YourViewController.xib
YourViewController *yourViewController;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) //This is iPad
{
// iPad-specific interface here
yourViewController = [[YourViewController alloc] initWithNibName:#"YourViewController-iPad" bundle:nil];
}
else // This is iPhone or iPod
{
// iPhone and iPod touch interface here
yourViewController = [[YourViewController alloc] initWithNibName:#"YourViewController" bundle:nil];
}
Let me know if you need more help.
just select device family as universal while creating the project,
watch this screen shot
well you need to create two xib's, one for iPhone and one for iPad and just use
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
here open your iPad xib
} else {
here open your iPhone xib
{

Converting IPad App to Universal App

We currently have an app that targets the IPad. We now would like to target the IPhone aswell. Im just wondering how we go about this? UI layout and functionality will be different but under the hood they will be sharing a lot of the same code.
Am I best creating a Universal app? or having to seperate apps one for the ipad and one for the iphone?
Any help will be greatly appreciated.
Thanks
Use these two macros
#define FOR_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define FOR_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
if(FOR_IPAD)
//load view for iPAD
else
//load view for iPhone

different status bar style for iphone/ipad in universal app

I recently updated my iPhone only app to an universal app and successfully submitted the update to the appstore.
however, the UI-Designers behind the project would like to have individual status bar styles for each app. So the iPhone UI should have a solid black status bar where the iPad implementation should have it semi-transparent.
is there a way to tweak key/value-pairs in the info.plis file to achieve something like this?
thanks a lot for your ideas,
sam
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// The device is an iPad running iOS 3.2 or later.
}
is recommended way of testing the device is iPad for iOS SDK >= 3.2
Use UIDevice class to get device model type in your application
NSString* deviceType= [[UIDevice currentDevice] model];
NSString* iPad = [NSString stringWithString:#"iPad"];
Now set the style of your status bar as per the model.
if([iPad compare:[deviceType substringWithRange:NSMakeRange(0,[iPad length])]] == NSOrderedSame )
{
//This is iPad
}
else
{
//This is iPhone/iPod
}