IPhone 5 optimize old xib - ios

This is my problem: I need instructions on how to fix the 3.5 inch xib for the 4 inch screen. I have already loaded the Default-568 img so I no longer have the letterbox layout.
I have the traditoinal 3.5 inch scren XIB and everything is perfect.
But when we turn to the 4 inch screen there is a large space to be filled and if I rearrange the XIB file for the iphone 5 screen when I turn to the 3.5 screen I can't see the button. Does it makes sense? Also I want to support versions prior to ios 6.
What I need is a fix or code or anything for the IPhone larger screen to be distributed proportionally.I have been reading that a solution could be duplicating the original xib file and arrange myself duplicated file in a 4 inch layout but I could´t figure out how to let the IPhone make the decision of opening one of the two xib files existing.
I have been given this piece of code but I still do not know where to paste it. I tried in the viewDidLoad but nothing;
if(thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
NSLog(#"Ipad ");
}
else
{
NSLog(#"Iphone %f ",[[UIScreen mainScreen] bounds].size.height);
if ([[UIScreen mainScreen] bounds].size.height == 568) {
//this is iphone 5 xib
viewName=[[NSString alloc]initWithString:#"ViewControllerIphone5"];
} else {
// this is iphone 4 xib
viewName=[[NSString alloc]initWithString:#"ViewController"];
}
}
I don´t know where to put that code; I know it is in the implementation file but I don't know where.I don't want autoresizing masks
Please, I´ll be glad if you could help me with this problem. I need careful instructions as I don´t have a lot of knowledge in the topic.
Thanks in advance!

You have 4 options
1-) using a seperate xib file for 4'' screen, and in applicationDidFinishLaunching:withOptions method deciding which xib to load depending on mainScreen height.
2-) using auto layout ( only ios 6 + )
3-) using struts and springs
4-) calling a method only on 4'' devices, and setting view's frames and positions for 4'' display manually in that method

Don't have separate nibs for this case. Use your normal 3.5 inch layout and use auto layout or springs and struts (under the dimensions tab for each object) to make the view resize correctly.
Check the Apple docs on Auto Layout and Springs and Struts for more info.

Related

issues with button in uiimage in Xcode

I have problem in xcode, I'm trying to add button in the image but the position comes in the different positions from iPhones screens
Here is the picture from my storyboard:
http://ya-techno.com/up//uploads/images/yaTechno-cb6317a232.png
and here are the preview from others screens :
iPhone with 3.5 and 4 inch screen:
http://ya-techno.com/up//uploads/images/yaTechno-51f7ca836e.png
and this iPhone with 4.7 and 5.5 inches:
http://ya-techno.com/up//uploads/images/yaTechno-0a9210e0e5.png
I'm using the auto layout.
help :(
You have to use auto layout and there's no other way unless you write a very ugly code where you hard code the center for those buttons for each screen size!
I recommend reading about auto layout, it is little weird to start but you will get used to it after a while
here's a very good tutorial which helped me a lot http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1

iOS Development in Preperation for Larger Screen

In preparation for a possibly bigger screen in the iPhone 6, we can obviously programmatically base layouts around screen bound size, but how do we ensure the custom xib files are formatted? For example, I have a custom UITableViewCell that is set to 320x145 in storyboard. Can I somehow prepare this for a different sized screen?
Have you looked at the new Xcode6 beta? As far as I can see, we are able to create freeform views there in storyboards:
Looks like this (+ Auto Layout) allows us to be prepared for flexible interface types.
If you truly need to prepare for something that is rumored, I would suggest the same methods that everyone used when preparing for the iPhone 5:
Download and install latest version of Xcode.
Set a 6-inch launch image for your app. This is how you get new screen height (without it, you will get 1136 px with black margins on top and bottom).
Test your app, and hopefully do nothing else, since everything should work magically if you had set auto resizing masks properly.
If you didn't, adjust your view layouts with proper auto resizing masks or look into Auto Layout if you only want to support iOS 6 going forward.
If there is something you have to do for the larger screen specifically, then it looks like you have to check height of [[UIScreen mainScreen] bounds] (or applicationFrame, but then you need to consider status bar height if it's present) as there seems to be no specific API for that.
Example:
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == new screen height) {
// code for 6-inch screen
} else if (screenBounds.size.height == 1136) {
// code for 4-inch screen
}
else {
// code for 3.5-inch screen
}
The absolute best thing that you can do this time around (not just doing a bunch of if's everywhere) is to use Size Classes in your Storyboards.
Whats new in Xcode:
Size classes
Size classes for iOS 8 enable designing a single universal storyboard with customized layouts for both iPhone and iPad. With size classes you can define common views and constraints once, and then add variations for each supported form factor. iOS Simulator and asset catalogs fully support size classes as well.

Modifying an existing 4-inch storyboard to work on a 3.5-inch screen [duplicate]

This question already has answers here:
Supporting Multiple Screen Sizes in Storyboards (3.5 and 4 inch screens)
(2 answers)
Closed 9 years ago.
I am programming an application (my first) for iOS 7 using Xcode 5.0.2, and I think I may have made a mistake in designing the story boards on the 4-inch display first, because I want my application to work on both the 3.5 and 4-inch display.
Do I have to create a new story board for the 3.5 inch, or can I use auto layout to configure what I already have? If I can, how do I configure it? I've used auto layout before, but not to support different screen sizes, only for changing from portrait to landscape.
If I have to create a new storyboard, do I have to create new classes for those or can I somehow link to the code I've written?
Autolayout is designed for just this sort of thing. If you have set it up for changing between portrait and landscape, it should Just Work when changing between 3.5 and 4 inches. If not, please post a more specific question!
If you are using storyboard, as #hatfinch mentioned it will work out of the box. You might have to go modify your constraints to make sure it look okay on 3.5 inch screen.
You can see how your views will look like in 3.5 inch by following ::
Select your storyboard.
From Editor menu, select " Apply Retina 3.5-inch Form Factor".

storyboards, InterfaceBuilders, 3.5 Vs 4 inch screen

I am working on a UI that will live on different sizes of iPhone retina ( 3.5 and 4).
I am using storyboards, now in every viewcontroller I add in Interface builder, I can select the size under simulated metrics, and one option says retina iphone 3.5 screen. which is what I chose.
I then setup constraints for the view controller to maintain top and bottom space to superview. Thinking that with this setup it will work fine on iPhone 3.5, and then resize properly to iphone 4 inch screen.
its not working, do I have to resort to code and do this in viewdidload?
Switching from 3.5" to 4" screens is only made for you to take a look what changes with your layout, how is it resizing. Same goes for Portrait and Lanscape orientations in each viewController.
In order to use autoresizing behavior you have to use strurs and springs on ios5.
If your project's deployment target is ios6 it is recomended to use autolayout.Though it is a little bit more complex and hard to understand, especially using autolayout constraints in code, autolayout saves much time that you would spend to make dynamic things resize properly.
I use this same approach. It works well so lobg as you use autolayout correctly. Play around with the constraints and you'll learn quickly how yo do the layouts efficiently.

Same xib for iPhone4 and iPhone5 possible?

Is there any way I can design my classes for both iPhone4 and iPhone5 using the same xib?
Yes, you can use the same XIB to design for iPhone 4 and iPhone 5 by using Auto-Layout.
Build an app using iOS 6 as the Base SDK and use the Auto Layout feature to make screens that can scale for all type of screens. You'll need Xcode 4.5 to do this.
Get started with Auto Layout here:
http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2
http://www.raywenderlich.com/20897/beginning-auto-layout-part-2-of-2
Well short answer to you question is YES;
Long is :- If you user XCode 4.5 and build app that is universal the NIB files and Classes would work perfectly for Iphone 4 and Iphone 5; Understand for you it important to know the version of SDK of these mobiles not the mobile version them self.
Another thing is that iphone 5 size is little bigger then iphone 4 so you need to design accordingly.. please read my answer at Iphone 5 screen resolution issue for better understanding.
Also look at the How to develop or migrate apps for iPhone 5 screen resolution? answer for more clarification on universal app desing.
Add a image named Default-568h#2x.png. That will identify your app as one that supports iPhone 5 metrics. And also you need to do auto sizing of your views properly.
yes it is possible,
just remove the side angle and make object free by enabling inner arrow.
so it will automatically resize according to screen.
but remember one thing that this will only work when you provide all default or any other splash screen.
If you want to make some small changes(e.g images position and sizes, scroll view content insets..), you can use codes to differentiate between iPhone 5 and iPhone 4/4s, and implement your codes inside the if/else statement.
Use this:
https://stackoverflow.com/a/12447113/1371949
to detect the iPhone type.
You can use auto layout feature provided by apple. Please refer to apple document for this:-
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/Introduction/Introduction.html
Please define below line and check condition based on device.
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
if (IS_IPHONE_5) {
btnBookmark.frame=CGRectMake(0, 460, 100, 70);
btnBookmark.frame=CGRectMake(150, 460, 100, 70);
}else{
btnBookmark.frame=CGRectMake(0, 360, 100, 70);
btnBookmark.frame=CGRectMake(150, 360, 100, 70);
}
Use AutoAutoresizing so that u can make app compatible with both iOS 5 and iOS 6. This is easy if your layout is having minimum dependancies. And this is possible for fixing issues with components like UIToolBar. Buttons in iPhone 5.

Resources