iOS 8 Adaptive layout and constraints on custom design - ios

I am trying to use Adaptive Layout to upgrade my project for iOS 8-9.
I have read and watch a lot of tutorials but all of them are explaining how to adapt a simple design with rectangles and centre them on the screen.
I don't know why I find it so difficult to understand how it works for my design.
This is my design in storyboard and how I would like to appear on all of the iPhones in portrait mode:
Can someone guide me how to properly build the constraints on this View? I might be able to understand the logic of constraints for real designs rather than rectangles which are centred in the screen. shall I start to design from Compact&Regular?

Here are the views laid out for different iPhone screen sizes in portrait mode. I have made some assumptions about the rules for the placement of the views. You can see the constraints also in the screen print.

Related

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.

The best way to make a viewcontroller for different screens

I would like to know which is the best way to make a view controller for iOS 9 swift 2 xcode 7, for different iPhone screens?
I have tried to make it with constrains but from iphone 4s to iphone 6s screens we can see wide gaps between the icons and text fields etc.
What i'm thinking is to make different view controllers for each screen (5.5inches, 4.7inches, 3.5inches) and to make my app check with which screen the user is opening the app and load the unigue view controller for this screen.
Or maybe there is a better way but im new to swift 2.0 so i'm asking for your help!
Thanks a lot for your time.
You can make a views for multiple screens using autolyout and size classes. You have proportional constraints that fit on all screens.
Proportional constraints means you can set for example view1 is 50% of screen.
These constraints fit on all screens.
Avoid excessive use of size classes (applying constraint in different size class). Try to go with proportional constraints in hAny wAny layout.
Only go for different size class if design on ipad is different then iphone. Or if you need different font sizes on different devices.
https://developer.apple.com/library/ios/recipes/xcode_help-IB_auto_layout/chapters/EditingConstraintAttributesintheAttributesInspector.html
I think this depends upon what your requirement is and what you prefer.
I usually prefer the good old Springs and Struts.
They can be used by disabling auto layout and screen sizes.
Using Springs and Struts i only create a single Storyboard to manage all iPhone and iPad screen sizes without any coding effort.
No matter how complex the UI maybe, for me Springs and Struts are the best solution.
Size classes give you a more fine grain control for different sizes and orientations. Please refer Apple's documentation
As I understood your question that you want to load storyboard as size of screen of device.
I will suggest you to refer this link to load a different storyboard depending on screen size. Sorry for Objective c but hope it helps you.
Load different storyboards

Autolayout(xcode 6,swift)

In I phone 5s simulator its working fine! I have one label,one image view and one button.As you can click on the link and see the picture now so i tell you that I used my image view as a background and the label is in the middle and the button is in the lower middle so i want that to look same in all the devices. i don't know anything about constraints.I am using Xcode 6
https://drive.google.com/file/d/0B2z_d4wEKPEFLV9RNFVlR3A5SFppa0tJT2tiQkQwVVVVTDVz/view?usp=sharing
I suggest you to take a look at this youtube tutorial. I learned how to make the constrains by watching it. The tutorial teaches how to make the similar layout as you required.
Link: https://www.youtube.com/watch?v=RpMzEmF-xZM
Hope this is helpful~
Autolayout is the tool used to make UI look similar across all devices, you should try to learn it if you want to continue to develop IOS apps. The concepts are pretty basic and are used throughout other languages.
This tutorial is useful if you want to create the auto layout using storyboards.
This tutorial is useful if you are making the view programmatically. I tend to use code for auto layout but it is just a preference, storyboards is fairly simple so I would suggest that. If you are going to do it in code a is to forget setting the autoresizing mask into constraints to false. You have to set this property on all the views you want to use auto layout for.
view2.setTranslatesAutoresizingMaskIntoConstraints(false)
Background ImageView
Select Image ->Pin->Uncheck Constraints to margin-> select top,bottom,left,right.
Button
Select Button-> Pin->Uncheck Constraints to margin->select bottom,left,right,Height.
label
Select label->Align->Center horizontally and Center Vertically in Container.
Pin->Width,Height.
If it is working for iPhone 5 but not another layout then this is probably happening.
There are demensions in the centre of the lower tab bar of story boards
There are screen size settings in the story board and regular*regular is the only one that is universal to all orientations and sizes of the ios device. if you set constraints while viewing in regular by compact (landscape for 5.5 inch iPhone) then those constraints will only be apply to 5.5 inch iPhones in landscape and if you tried running on a smaller iPod it would be as if you never set the constraints. the constraints for the 5.5 inch iPhone would not apply to the small iPod
if constraints were made in compact by compact and you were viewing the story board in say regular by compact then you would get an error saying that things are misplace and will not appear in the same at runtime. view the storyboard in the same dimensions that you set the constraints and you should not have an issue.
There is an option to simulate the device you want to run on specifically in storyboard and it can be say only 5.5 inch iPhones or something, whatever device.
go to paul hegarty developing iOS apps with swift on iTunes you if you want to learn more. He is a good source.

Auto layout or Autoresizing

I'm starting to develop an app that will only be on iPhone and only portrait view. I'm wondering the best way to develop an interface for both iPhone 3.5 inch and 4 inch screen. Every tutorial i see for auto layout seems to use it for portrait to landscape, but for me that doesn't matter because landscape isn't an option. I'm just wondering if I'm only using portrait is it easier to go with auto resizing?
Edit: I'll be using some UI animations in the project as well.
That depends on how your view sizes and positions relate to each other. If you want to align various views, or have views move when the text in a button or label moves then auto-layout is your friend. If you just want to resize a scroll view to fill the available space then auto-resizing is much simpler.
Arguably, learning auto-layout on a relatively simple app is a wise move to support your future app building endeavours...
If you want to make a relation between subviews and superview go for auto-resizing.
Otherwise if you want to make the relation between view or their neighbors view or adjacent view then go for auto layouts.
Auto Layout, because new features and functionality will be designed to work with Auto Layout, and your app will be more likely to be laid out correctly on upcoming devices or operating systems.
A case in point for iOS 8 is Adaptive UI. Apple has figured out and handled most of the edge cases, and content adapts to its view controller being collapsed or separated, remaining properly sized regardless of the device orientation or size. One code base. No conditional code required.
When Apple comes out with a new device or operating system, it's more likely that your app will behave more robustly if you use Auto Layout. If you size things yourself, you may overlook an edge case or not be prepared for a new size class, and your layout might break.
It comes down to how much code you want to write, support, and upgrade, versus letting the SDK figure out sizing, positioning, and relationships for you. Does their code have bugs? Yes. Does our code have bugs? Yes. Either way, it's not a perfect world. But anyone who adopted Auto Layout earlier, got a lot of functionality for free later. I believe adopting Auto Layout and size classes will continue to pay off, even at this stage.

UIViewController Size doesn´t work

Hi im currently developing an Universal app for iPhone, iPod and iPad. I have all view controllers in both storyboards set to Inferred. It works fine on iPhone Retina and on all iPads but when you put it in landscape mode it gets all messed upp and on the iphone 3,5 inch simulator the bottom gets cut off. How can i fix this? Do i have do create seperate view controllers for landscape mode and iphone 3,5? And the write some code that recognizes if its in landscape mode and iphone 4? I thought this worked automatically. Or have i done something wrong?
There is no quick fix/answer to your question.
Since the screen size is different while using horizontal and vertical orientations - it is simply not the same canvas and thus you will need to do some manual work to set it right.
Strategy 1.
Assuming your layout is simple - there are not too many elements and all elements can theoretically fit both horizontal and vertical screen size:
You should use auto layout from the Interface builder - Look at an excellent video from WWDC
https://developer.apple.com/wwdc/videos/
(video 406 - Taking Control of Auto Layout in Xcode 5)
In few words - you set spacers to your elements, aligning them to the end of your view (dynamically), therefore you can make your element shrink and move automatically respecting the current screen orientation.
Strategy 2.
Assuming your UI is complex and will not fit both orientations:
have a different xib file for horizontal and vertical views, this can take some time, but it is a solid solution that always looks good.
You simply need to track changes in orientation and load the appropriate xib.
Your problem will only be solved if you use Autolayouting and for that you need to go through some tutorials
Ray's Tutorial
Another Very well explained tutorial
Going through the above articles will definately help you in solving your problem

Resources