Application background for iOS application on both iPhone4(s) and 5 - iphone

I am trying to make a GUI for my first Objective-C application. However, I am kind of stuck at the background.
I need to apply a background which'll work on both iPhone4(s) and 5. How do you do that? I guess resolutions aren't the same on the devices.

There a couple different ways of doing this. One is to create separate storyboards/xibs for each screen size. Another is to use the condition:
if([[UIScreen mainScreen] bounds].height == 568) {
//
}
Or, if your background is a pattern image you only need to apply it once and it will work on both screen sizes, it's as easy as:
[[self view] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"myImage"]]];

Just create the background image for the size of the iPhone 5 and set the frame for the size of the iPhone 5 as well.
When the app is opened on the iPhone 4 it will truncate the bottom piece of the background-- it won't skew it.
If you are using Storyboards, there is a very useful button in the bottom right corner when the storyboard is open (next to the zoom buttons):
Toggling this will expand/contract your ViewControllers so you can see how it will look for both 3.5 inch (iPhone 4-4s) and 4 inch (iPhone 5) displays.

Related

How can i design Single xib for iphone3.5,and iphone 4 inch screen (ios6 and ios7)?

I created my application as tabbar application with iphone screens. It works well earlier. Now i want to change my tabbar application to support for iphone3.5 and 4 inch screen (in ios6 and ios7). In past i have designed only single xib for this.
is it possible to support all those screens with single xib? Please help me on this.
Notes:
I have latest xcode5. I have tried autoresizing , but it is very difficult to understand. Because its work for 3.5 inch screen and 4 inch screen in ios6 but view goes out of the screen in ios7.
That's not because of the size.
In iOS7 both top and bottom bars are transparent.. That's why your views get resized and covered by the bars.
To fix this simply add this lines to your viewDidLoad method:
if ([self respondsToSelector:#selector(setEdgesForExtendedLayout:)])
self.edgesForExtendedLayout = UIRectEdgeNone;
if ([self.tabBar respondsToSelector:#selector(setTranslucent:)])
self.tabBar.translucent = NO;

Converting ipad app to iphone5

How can i modify my code so same app can run on iphone with same UI elements.
I made changes in info Plist and made it universal but Problem is that i have not used stroryboard or nib , xib files to display UI elements. also i hardcoded the height and width for particular button or label ,frame etc.
So is there any way to auto resize screen to ipad view to iphone Or I need to write every code with new height and width for iPhone?
like in android i detect the height and width and according to that i divide it by 2 or 3 to place particular UI item on different screen size.
Also how can i detect that app is running on iphone 4 or iphone 5 or iPad so i can change my images and value or height n width?
You can get the screen bounds using:
[[UIScreen mainScreen] bounds];
The quantity of changes that you would have to make depends on how you designed your code before, if you were using absolute values all the times you'll have much more problems than if you were using relative values...
you can take a look at the UIViewAutoresizingMask property of your views, for example:
view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
as to how to check if you are on iPhone 5 you can use this line of code :
BOOL isIPhone5 = [[UIScreen mainScreen ] bounds ].size.height == 568 ? YES : NO ;
Create seperate nibs for iphone and ipad
well doing it all codewise then you have to set the frame for all the components code wise checking the device is ipad or iphone.
Checking iPad or iPhone look here

iOS 6 4inch simulator - tab bar not responding

When I run my iOS app designed for Iphone 4S and earlier on the iOS6 4inch retina simulator, I get purple bar underneath the app content with the tab bar at the bottom. The tabs do not respond. I have added the Default-568h#2x launch image which fills up the screen but my content does not resize even though most nibs are set to AutoResize subviews. Also the keyboard does not come up from the bottom when I tap in a text view.
Is the simulator buggy? I thought apps if not modified would run with black bars in place of the extra screen size. With the simulator like this I have no idea how the app would look on an iPhone 5.
Thanks
The UIWindow containing your UITabBarController has a frame size smaller than the iPhone 5 resolution supported in iOS 6.
To resolve this behavior, set the property in Interface Builder of the UIWindow->Size to be Retina 4 Full Screen
Alternatively, to handle this in your code, set the frame to the main screen bounds:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
Once I did this, my UITabBarController began working again as designed.

Extend app for iPhone 5 - best practice

Now that Apple is about to start shipping iPhone 5's, I'm looking into extending my applications so they appear full screen on the iPhone 5. I ran my apps on the simulator, and even the ones with a UITableView extending to the bottom of the screen, the black bars appear at the top and bottom of the screen.
Here's my question: What is the best practice for extending apps for the iPhone 5?
Should I make a separate nib now for the 3.5 and 4 inch screen, or extend everything in code?
I'm trying to make this as smooth a transition as possible, so I appeal to knowledge of SO to clue me in onto what the best way is to build for both screens.
Taking advantage of the full 4" screen in your apps seems to be as simple as adding a new Default image named Default-568h#2x.png with size 640 x 1136. Xcode 4.5 will actually offer to do this for you automatically by adding a black image of the proper size and name to your project.
For apps that use standard UI components, such as table views, the tables are magically extended to fill the screen. I updated an app for work and it was literally this simple, with only a couple minor issues related to my own code and UI setup. But all in all, very easy.
Contrast this with another app I work on (for myself), which uses none of the standard UI components except for UIViews. To deal with both 3.5" and 4" screens, I have had to spend quite a bit of time refactoring code that needs to know screen size for various operations of the app. (The app in this case is more of a game/simulator than say, a productivity app.)
So, your mileage may vary with regard to the level of effort really required to support the 4" screen. It will depend on how complicated and "non-standard" your app is, as I have discovered.
When updating an existing app for the larger-screen iphone 5, you may also find that the bottom of the screen is not "clickable". For example, if you have a toolbar along the bottom of the screen, that toolbar would be displayed correctly, but buttons would not react to the touch. If this is the case, you need to tell the app that the window is using full screen.
If you have MainWindow.xib, open it, select the window and in the attributes inspector make sure that "Full Screen at Launch" is checked.
If you don't have MainWindow.xib in your project (and most newer projects don't), then you need to add one extra line in the applicationDidFinishLaunching of your app delegate:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window setFrame:[[UIScreen mainScreen] bounds]];
...
}
I put it in the beginning of the method. Worked like a charm.
You will find this path with simulator XCode->Targets->Summary->iPhone/iPod Deployment Info( the Retina 4-inch )
You need to add a Default image with size 640 x 1136.
Apply this code in your AppDelegate file
mainWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
mainWindow.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
You will get the main screen size of your window. one more thing whenever you want to check in your class file just add this code
if ([UIScreen mainScreen].bounds.size.height > 500.0f)
For your view controller just add one property autoresizingMask
self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
This works fine for me.
I was looking for the same issue, trying to get iPhone 5 (4") to render my xib files to full screen, and I found this answer, which says you only need to add the Default-568h#2x.png image to tell the iOS that it needs to render your app in 4" fullscreen. just adding this fixed the problem for me.
Why [UIScreen mainScreen].bounds] is not returning full screen size?

Struggling with making my app displaying properly on iPad

I have a little trouble grasping the concept of making views that will display proper on iPhone, iPhone 3G(s), iPhone 4 and iPad.
Lets say I have regular UIImageButton at a position of (200, 300), and size is (100, 60).
If I define those values in CGRect structure the button will scale properly on iPhone depending on whether or not it is with iPhone (320px, 480px) or iPhone 4 (640px, 960px). I only need to provide a extra set of images with the doubled size since I am not specifying real pixels but points.
However on iPad this does not work, or else I am doing something wrong because it does not display properly.
I want to know if there is possible to specify that the imagebutton in this example would stay at the same location as on iPhone. I also need to know how I should "properly" initialize a e.g. UIImageButton. Is it correct to say
[[UIImageButton alloc]
initWithFrame:CGRectMake(200.0f,
300.0f, 100.0f, 60.0f)];
if I want to have it located on the same location on the iPad version. Could anyone explain? Thanks in advance.
It's easier to do this in Interface Builder. Select the view, and in the Inspector click on the tab with the ruler (third tab in). The "Autosizing" section lets you control how the location and size of the view changes depending on the device and orientation.
To do this in code, you change the autoresizingMask property of the UIView, e.g.
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight