I am building a single view application with 12 different view controllers. I built all of the view controllers in "any width" and "any height" and added all constraints for each page and also first ran the simulator with an iPhone 6. However when I switch to other devices to run in the simulator, smaller and larger, the images I have on the view controllers become very distorted and the font sizes become disproportioned with the rest of the screen, despite adding in all necessary constraints. Do I have to redesign each view controller to fit each size (for example regular width and regular height for iPad or compact width and regular height for iPhones in portrait, etc.)? Or is there another way to maybe get all of the images/ font sizes into proportion with each screen size, again small and large? Thanks
Constraints are fine in this case, you shouldn't have to redesign every view for each device size. For your images, try changing them from size to fit to aspect fit or aspect fill in the right-hand pane in Storyboard. This will keep their aspect ratios intact. I suggest starting out with using reset to suggested constraints on all views that you can before you fully get the hang of constraints. This will generally work most of the time.
Related
I have a login layout and I want it to work universally on 4 inch, 4.7 and 5.5 inch screens.
I want everything to be as if the screen was "one" and I just made it all x% larger or bigger to stretch and fit the screen.
Part of the challenge in doing this is that different components are adjusted in different ways to scale with screen size, as well as that there are a few ways to do some of those.
Lets look at a few:
You can use Autoresizing to scale a view automatically with with the size of it's superview/container (so this applies to changing from portrait to landscape). You can find this in the size inspector (if you haven't set constraints). You can see an in depth tutorial on it here.
This let's you set both spacing and internal space based on where you place the view originally.
Another way is setting constraints in relationship to another view with a ratio other than 1:1. For example, you can set a constraint of your button to the superview as equal widths and edit that constraint's ratio/multiplier to 1:2 to make it 50% the size or 1:4 to make it 25% of the width, etc'.
For the fonts you should probably use Autoshrink. You can see a detailed answer about this here.
Auto layout makes things easy but still confuses me a lot when it comes to landscape orientation. I have to keep both landscape as well as portrait screen. My application will be for iPhones only i.e from iPhone 5 to iPhone 6s+.
What size class I need to use? everything seems so confusing. Every constraints conflict with each other. I have no problem in understanding leading, top, bottom, trail space. But what if device is rotated? How do I manage things? Please help!
I don't think you'll need size classes unless you're sure that there's going to be a significant GUI variations between different screen sizes or rotations.
In terms of rotation, the constraints don't change their orientation when the device is rotated. They still stand for what they stood for before.
For size classes, it depends on the app's design. Most likely, if you've setup your constraints correctly, you'll be fine with just a single size class for an entire family of devices.
If you choose to, for example, have significant changes in a tablet-focused variation, you can make those in code depending on the device type or screen size, or use a size class. Only use a size class to have variations in layout between various screen sizes that cannot be handled with constraints alone.
This site is a useful visual reference for size classes.
If you're making an iPhone-only app, what you basically need to know is that every iPhone uses regular height in portrait, and compact height in landscape. So focus on those two size classes.
Set the storyboard size class (in the bar under the canvas) to wAny hRegular. Then select your view controller and (in the Attributes inspector) set the size to iPhone 4-inch (or other device of your choice) and set the orientation to portrait. (These view controller settings don't interact with the size class but make it easier to see how things will look at runtime.) Now set up your portrait layout constraints.
Then set the size class to wAny hCompact. Change the view controller's orientation to Landscape. Now set up your landscape layout constraints.
I'm new to iOS development and I'm having some issues with the auto layout feature in Xcode 7.
As the image attached, my circle progression view doesn't scales fine for the 3.5" iPhone and it certainly looks fine with the other size classes.
Is there a minimum size limit for UIView in Xcode?
Also there are two text label in the circle view and no matter how I constraint them, their size just won't change across iPhone size classes.
As you might notice I have a SOS button which is a button embedded with an image I designed. I have added some constraints similar to the circle progression view but it doesn't work at all.
Is there any good guides/tutorial where it specifically teaches how to manage iOS element sizes across all iPhone size classes?
You can set the controls heights and the spacing bitween them to be related to the main view height. That will make them shrink little bit in 3.5 inches screen. You can then play around the constraints values to find the most convenient to you. like this
So I've spent a lot of time creating an app and I noticed that I've been building it on a compact width and any height base values. Can I keep my changes and set it to any width and any height? Because now when I change it to that all my changes have disappeared. (my changes are EVERYTHING, I started making the app using compact width and any height)
Or will I need to switch to any width any height and restart my entire app? :(
please help
A size class doesn’t necessarily map to one device in one orientation. For example, an iPad can have a view with an iPhone style layout (i.e. compact) when presented in a smaller space and an iPad style layout (i.e. regular) when the space is larger.
This means you can have a unified storyboard when building a universal application.
If you think there's anything wrong with it you can disable some constraints. These constraints won't apply to your current layout but still work for others. You can add some new constraints and the new constraints will work at the current size class.
I am struggling to use Xcode 5's constraints to fit content (relatively) between 3.5" and 4" screens. To simplify matters, I am only concerned about portrait at this moment
Here is an example screen of a layout on a 4" screen (the tab controller at bottom isn't shown):
I want to lock the proportions of any images (such as this truck), but allow all labels, buttons etc to squeeze more closely together on the 3.5" screen. As all iPhones are the same width, I think I need to leave the x-constraints as-is, but configure dynamic y-co-ordinates, but would appreciate advice on this.
Many thanks.
You can pin the width and height of your image in your storyboard by selecting the image and then adding the necessary constraints (your numbers will be different):
You can add constraints to automatically change the vertical layout by making the relation by "greater than or equal" or "less than or equal", but, in my experience, it is difficult that the result is exactly what you want, as the autolayout engine will not make the line separations the same.
My suggestion is that once you have the layout for one of the screen sizes, you add outlets for the vertical constraints and then adjust those constraints constant property in code on -viewDidLoad. That way the distribution of space will be exactly what you want.