UITextfield Custom Position moved up because of different iPhone sizes - ios

I have several custom UITextfields in my app. I started this app on Xcode 5 and ran on iphone 5 simulator. After Xcode updated to Xcode 6, I ran the app on iPhone 6 simulator. Now all the textfield positions moved up because of large screen size. I just wanted to know is there anything I could do so that the positions of textfields automatically get adjusted depending upon the iPhone models.

You need to rebuild your interface to handle the different screen sizes. In particular, you need to work with the AutoLayout feature to help determine how you want everything to scale/move/position based on multiple screen sizes. This can be done via the Storyboard (easier but sometimes frustrating) or in code (harder at first but more control later). I usually use Storyboards and it's worked great on several projects.
Do you want it centered and respecting your original layout and margins? a certain distance from the top or sides? everything scaled up appropriately? All these things can be done with AutoLayouts.
Check out the great tutorial here for more information:
http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1

Related

(XCode Autolayout) Label/Button position&size keep changing over time

Hi I'm new to Xcode and I have been checking out ObjC tutorials lately and I started playing around with the storyboard.
So What I did was:
Drag some buttons/labels onto a view in storyboard
Set the size & position using the size inspector
Build and preview the app on the iPad
It looked fine at the beginning, but then I noticed that the position and size of the buttons/labels kept changing over time (by like a few pixels) as I built the project for a number of times.
I have not change (or set) anything about insets/constraints yet.
Can anyone please advise as I dont think anyone would be happy for changing the position & size when there is over 100+ UI elements.
The thing is that you have created the layout for one pixel density and implement on different pixel density. Which means you to exactly see what you are making build the layout in also ipad (you can change it in the storyboard see below).

Manually adjusting positions of UI elements in Xcode's storyboard

Instead of having to use xcodes constraints, which I can never get to work right, is there a way to manually set where UI elements are on the screen? I noticed that if I'm on the attributes bar for the view controller, I can set simulated metrics's size to any iphone size I want.
Then I can position the UI elements on the screen where I please. When I build and run, it always mimics exactly what I set up. However, it only works for the particular size of the iphone I specified. Is there a way to do all the sizes manually without making several xcode projects?
Thanks!
There is multiple other solution that is not as good as constraints.
1) Use frame property of views to place them
2) Use size classes to do different placement for iPad iPhone etc
3) Use suggested constraints - you are placing views and than you can give XCode possibility to create constraints for you suggesting what you want from your views placement.
You're going to want to learn how to properly use constraints. The approach you're trying to do would have been okay when there was only one screen size, but now we have three different sizes of iPad, two watch sizes and four different iPhone sizes. Here's a link to a tutorial from Ray Wenderlich (he has some pretty good tutorials to get you started n a wide variety of things). https://www.raywenderlich.com/115440/auto-layout-tutorial-in-ios-9-part-1-getting-started-2
The auto layout in storyboard on Xcode 7 isn't my favorite, but when Xcode 8 comes out it provides device specific sizes for views that makes auto layout much easier. So maybe Xcode 8 will provide a better solution to your problem!

How to support one xib for all iPhone devices upto iPhone 6 Plus?

I started one new iOS apllication. And that application requirement is app should support from iPhone 4 to iPhone 6 Plus. I am very much familiar with using Xib files. So far I differentiated my apps with iPhone 5 and below iPhone 5. For that I Used 2 Xib files for one is for iPhone 5 and other is iPhone 5 below according to device height I added like that. But now apple has relased iPhone 6 and iPhone 6 Plus with iOS 8 along with XCode 6. For these 4 types devices,
1) iPhone 4 2) iPhone 5 3) iPhone 6 and 4) iPhone 6 Plus do I need to add 4 Xibs or any other solution.
To learn Storyboards, now I don't have that much time because my app has already release date confirmed from Client. But I will learn about sotryboard in future definately.
I have tried with Autolayout concept, but its not worked for me. and I dont have full awarness on Autolayout concept also. Yesterday I started my new project with XCode 6, So I taken iPhone 6 view and tried to use autoresizing and autolayout but not worked for me and views are overlapping. I know for different devices creating different xibs is not good practice. For creating each device with each xib would take huge time. I am really bothering about this how to handle different devices from yesterday onwards. Please somebody help me to came out from this issue. Really highly thankful to you. If anything mistakes in my content please forgive me.
Your question deserves a longer answer than StackOverflow can provide, but there are a few pointers I can give you.
For each of your xibs, enable Size Classes and Autolayout.
Set each xib root view's size class to width Any and height Any, which I believe are the defaults.
Design your interface in a way that looks decent on this theoretical Any x Any device.
I highly recommend using a UIScrollView at the top level of any view controller's view hierarchy.
Use constraints to anchor the controls. I find it easiest to start with the control in the top left corner, anchor it to the containing view's top and left sides, and then work your way down and across until all of your controls are constrained on all 4 sides, or on one vertical and one horizontal size, along with explicit height and width. Be generous with the greater-than and less-than relationships in your constraints.
To customize for each device layout, switch the size class to the desired combination. Note that any constraints you add, change, or remove, as well as any controls that you add or remove, will be changed only for the current class size. Do this for each different size class that you're going to support. See Apple's reference for which size classes are used for each device.
Test your layouts using the Resizable Device simulators.
This is hard work, but it sure beats having to maintain a different xib for each device size.

Fit an iOS application developed for 4 inch screen to 3.5 inch screen

I am writing my first iOS app and just realized a serious problem. I was using storyboard for a 4 inch iphone screen and forgot to take 3.5 inch screens into consideration. :( It seems that this could be relatively fixed easily if I have done everything in code. But unfortunately, I have used storyboard for some parts of my app. It seems that the table views are fit perfectly but the views with some fixed subviews fail. Could anyone please give me some suggestions on how to fix this? Any help is appreciated. Thank you very much!
This is exactly what auto layout exists for. You can create a UI, using storyboards, that works perfectly for both screen sizes. You can toggle a setting in the storyboard to have it display the two different screen sizes, so you can easily see how your views will move and resize. There is also a preview mode for the storyboard that lets you see how it will look. It also lets you see how it will look on both iOS 6 and iOS 7, so that you can make sure that your UI looks good on both assuming you still support iOS 6.
If you had done this in code, it would probably have been a whole lot more complicated, especially since you have to run it each time to see what changes when you adjust your code. Graphical layout tools such as Interface Builder (what allows you to view and edit storyboards and XIB files) make supporting multiple screen sizes very easy. Plus, generally it's not too hard to make a screen designed for a 4" screen work with a 3.5" screen, in some cases you just have to make things fit a little closer together, or perhaps have the content in a scroll view.

iOS storyboard layout

I am working on an app and have come into some graphical problems when designing my app.
First off, my app is only support by iPhone. My current storyboard is using the iPhone 5 as the screen size, so everything screws up when I try to run in iPhone 4 and 4S. Is there a way to make multiple storyboards for each different screen size? Or do you all have another solution?
Thanks!
- Brad
There is a way to make different storyboards for separate screen sizes, but another way to do it is like this:
Whenever you add objects to your views, be sure to have them aligned to something (using constraints). If all items are relative to other items, then most likely the layout will be fine on all devices. Also, if you find that your controls start overlapping, then perhaps you ran out of room. In that case simply add a scroll view to your layout, and then put the controls on top of it. Then, it won't scroll on the larger screens because all controls are shown, but on smaller devices it will allow you to scroll down to see the rest of the objects.
Good luck.
There is a small button in the lower right hand corner that lets you toggle between 3.5" and 4" screen sizes so you can see how it will look on different devices. By using Auto Layout introduced in iOS 6 you can make sure to set up your constraints so that your UI looks good on both older and newer iPhones.

Resources