Updating controller from iPhone to iPad with size classes? - ios

I have been using autolayout and constraints to make my app look pretty on every iPhone, and it looks ok so far. I am having problem with iPad. I have a screen that when viewed on iPad has to much blank space.
I would like to use bigger images, and larger font. Maybe add one more label. Can I do this with sizeclasses, or i have to do it some other way?

Yes, you can do all that with size classes – and indeed they are the preferred solution for this, because you automatically get support for slide over and split view.
If you're using Interface Builder (which, quite frankly, is by far the best way to work with size classes), you'll see little + buttons next to many configuration option of your user interface. For example, you mentioned larger font: right there to the left of the font options is a + symbol, and clicking it lets you add a different font size for specific size classes.
I made an app a few months ago that worked on all iPhones and iPads as well as Apple TV, all using the same base storyboard with customisations using size classes. There's such a big gap between the tiny iPhone 4s and the massive iPad Pro that size classes were basically essential. And yes, split view worked flawlessly out of the box, which was a bonus.
My primary advice: Design for your smallest screen first, then add size classes to configure the largest options. You can then choose some views to either not be installed (it's a checkbox) or just be sized down very small to make sure your UI looks and works great in its most challenging environment. If you can do that, making iPad work is a cinch because it feels like you have acres of space ;)
Another useful tip that enough people know about: Enable the assistant editor, then choose Preview mode for your storyboard. This lets you see how your layouts look on multiple different devices and orientations simultaneously, as you work. If you're looking to make best use of size classes (and the massive difference in space between iPhone and iPad) using the previewer is essential.

Related

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!

Building responsive layouts with AutoLayout

For the past few months, I have been trying to learn iOS development. Most of it has relatively easy, however, one thing has been very difficult for me. AutoLayout. After I grasped constraints, I thought it would be easy, but I am having real trouble getting my layouts to look well on both iPhone and iPad devices. I can design pretty well for iOS. Recently, I was building an app where I put two buttons in the ViewController. on iPhone, I set the constraints of the buttons to equal the width of the screen (plus the screen margin), and set a reasonable looking height to the buttons. On iPhones, my layout looks great, but on iPads (especially the newest iPad Pro), things look horrific. Full width buttons look great on the iPhone, but on iPad they need to be a lot smaller width wise and a lot bigger height wise. Likewise, my images look great on iPhone, but are too small on iPads. In CSS, I could just use MediaQueries, and on Android, resource qualifiers on the values and layouts.
What are my choices here? How can I design my layouts to look nice on both iPhone and iPad when certain dimensions need to be different based on screen size, screen resolution, etc.? Constraints seem to be good for enforcing dimensions, but not adapting them.(Except maybe the Aspect Ratio constraint)
What features of the AutoLayout system can allow me to accomplish responsive layouts among larger screens and Retina resolutions? What are some common tips / tricks for developing responsive layouts.
You can use size classes in order to build for different screen sizes easily. raywenderlich.com has a solid guide on adaptive layouts.
You can use size classes to design differently for iPhones and iPads and also you can use proportional width height to look perfect based on the height ratio of all devices. If you want to choose first option then you can go with any tutorial available but if you want to choose the second option which is the little difficult way but time saving way then you need to really understand the sizes of devices and need to understand what actually proportional width and height constraints do. Thanks.

Understanding IOS8 size classes

I have been playing around on Xcode with size classes to try and make sense of it. The problem I have is that many different sized phones all fit into the same size class (like all iPhones in portrait) so I can't home in on a 3.5 inch screen for example. This is frustrating as I would like to change the layout constraints between phones rather than just classes as obviously I need to make the gaps between things larger or the buttons slightly bigger to keep everything in proportion. I don't know if it is something I have missed but it seems the only way I can do this is by creating every single layout constraint I want to change as an outlet and then testing in code for each phone and updating it using a rough estimate and run the thing on the simulator.
In Summary, how can I adjust the constraints based on the size of a device, when they're all in the same class? Using a percentage/proportional constraint should give me the result I'm after.
Apple have designed it so that you don't have to think about specific devices. The idea is that you use auto layout so that each screen automatically adjusts to the available space. Size classes is an extension of that so when you get a lot of extra space you can do something slightly different.
If you want to customise your layout to specific devices, you can. Pretty much as you describe it. However, what happens next year when Apple release the iPad Pro and a 4.3" iPod touch (you read about it here first)? In general, there is no need to hard code spacing and sizes; your interface should scale to use the space available, and that's what auto layout and size classes give you.
It's certainly harder to think it terms of constraints rather than a list of known screen sizes, but it should be worth it.
Well, Size Class has many advantages. It depends on how people viewing it. In specific to your question there is a way to change for all iPhones in Portrait and all iPhones below 4.7 inch Size in portrait.Below is the image of that. I can understand supporting 3.5 inch screen with size class is difficult. Setting a proper constraint and using the below class will help you to achieve it.

Supporting multiple iPhone resolutions with a single storyboard

We all are going to update our apps to iphone 6 and iphone 6 plus. That means we need to support 4 sizes.
1.) 3.5
2.) 4
3.) 4.7
4.) 5.5
Can we support all these screen sizes with single xib or storyboard ? also please share your views on how we can update our existing apps for iphone 6 and iphone 6 plus.
Yes. See Apple's iOS8 documentation specifically, size classes:
iOS 8 makes dealing with screen size and orientation much more versatile. It is easier than ever to create a single interface for your app that works well on both iPad and iPhone, adjusting to orientation changes and different screen sizes as needed. Design apps with a common interface and then customize them for different size classes. Adapt your user interface to the strengths of each form factor. You no longer need to create a specific iPad storyboard; instead target the appropriate size classes and tune your interface for the best experience.
There are two types of size classes in iOS 8: regular and compact. A regular size class denotes either a large amount of screen space, such as on an iPad, or a commonly adopted paradigm that provides the illusion of a large amount of screen space, such as scrolling on an iPhone. Every device is defined by a size class, both vertically and horizontally.
There is also a very good tutorial video on the WWDC site.
In order to stop your iPhone 6/6+ app being scaled, add a launch image of the correct size or better, use a launch storyboard.
From there you should use AutoLayout and avoid hard coding to screen sizes. In the long run it'll be a lot less effort and less error prone.
In existing projects you can use autoresizing or auto layout of xib files.. that support all 4 devices.
I have implement my projects using autoresizing to support all devices.

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