-2

I am new to iOS. I am learning my self. No resource are to clear my problem.

I have two view with 270 X 338. that I have to keep in Horizontally in Viewcontroller. But, when I add some constraints it's not fitting for below 5s. I checked in simulator also in preview option.

When i use autoresizing, also it's not fitting for below 5s screen. Please help me with some idea. I need to do only in storyboard.

Thanks

I tried this tutorial Here but it din't help

This is my preview screenenter image description here

Edited:

enter image description here

Constraints for Back View;

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
Maddey
  • 63
  • 7
  • show your view controller image – Divyanshu Sharma Dec 29 '15 at 07:24
  • which constraints have you added in this two views? – Piyush Dec 29 '15 at 07:24
  • @PiyushPatel posted some tutorial link in above. They used some constraints ,that only i used – Maddey Dec 29 '15 at 07:28
  • @DivyanshuSharma i have added one image. in that when i tried to fit for all screen its not fitting well. in simulator below 5s its not fitting well – Maddey Dec 29 '15 at 07:29
  • are u fixing the width and height of those view? that will make ur view doesnt fit, u should only use aspect ratio and 4-side constraint – Tj3n Dec 29 '15 at 07:30
  • @Tj3n I added 1. `equally width` for 2 view. then for `first view` i added `Top, Left `constraints.Then for` second view` i added `right and top` constraints. At last i added `equal height` for `both views`. And for` first view` i added `nearest neighbour of right` – Maddey Dec 29 '15 at 07:33
  • do you want your width to be compromised? – Rahul Patel Dec 29 '15 at 07:34
  • @EICaptain I dont want to fill for whole screen i want it only half like my screen 6 size in my above image – Maddey Dec 29 '15 at 07:35
  • @RahulPatel .Compromised in the sense that?? – Maddey Dec 29 '15 at 07:35
  • I would suggest using UIStackedView for this which will help you to create two UIView of equal width and height. – Leena Dec 29 '15 at 08:21

3 Answers3

3

These steps will help you align two views.

  • Add top, leading, and height for first and second views.
  • Add trailing constraint from First view to Second view as 8.
  • Add Equal Width for First view and SuperView and set its multiplier to 0.49* and constant as 0.
  • Add Equal width for two views again by selecting two views.
  • Finally update constraints the view will align for all sizes.

    • 0.49 will leave 8 points as trailing constraint.

Constraints for First View

enter image description here

Constraints for Second View

enter image description here

Edit :

For third step you can do by selecting first view and hold Control button and and move mouse to super view.

enter image description here

The selected view in the below image is the Superview enter image description here

Rugmangathan
  • 3,186
  • 6
  • 33
  • 44
  • 3rd point is not clear for me. i select first view and tried to add equal widht. But that option is disabled. And what is that superview means?? – Maddey Dec 29 '15 at 07:54
  • Select First View and SuperView and add equal width constraint and select the constraint in size attributes, set multiplier of constraint to 0.49 instead of 1 and constant as 0. I have posted image for reference. – Rugmangathan Dec 29 '15 at 07:56
  • Or else you can do it by control + click form Firstview to SuperView which shows an action view select equal width in that – Rugmangathan Dec 29 '15 at 07:58
  • yes its clear about adding values. But superview is my second view are what??I am new to this. That why asking, does superview is my second view?? – Maddey Dec 29 '15 at 07:58
  • the background view(parentView) which is white color is the super view. The view at the top on the Document outline where you are adding two colored views as subview(child view) – Rugmangathan Dec 29 '15 at 08:03
  • no like my same image i have posted in my above post only getting. My uiview size is 180 X 225. – Maddey Dec 29 '15 at 08:07
  • @Maddey i have added image for reference – Rugmangathan Dec 29 '15 at 08:08
  • @Rugmanhathan Please see my updated post. I did all . But not able to get – Maddey Dec 29 '15 at 08:14
  • set constant to 0 for proportional width. As the iphone's have different screen sizes it will adapt to those sizes using auotlayout. Also set multiplier to 0.465 for having leading 10 points. – Rugmangathan Dec 29 '15 at 08:34
  • s i set constan to zero only. But not able to get – Maddey Dec 29 '15 at 08:49
1

Use leading, top and relative height and width constraint that will solve your problem... set relative height and width in view with autolayout from below steps

  1. Set equal height and width with superview.

  2. Go to properties of constraint where you find a property multiplier in which set exact multiplier value which you want or which satisfy your constraint.

  3. This will make height and width of view relative to superview that changes according to superview.

NSPratik
  • 4,714
  • 7
  • 51
  • 81
Divyanshu Sharma
  • 551
  • 2
  • 12
  • i am new to ios. Really dont know about to fix for leading top and relative hight and width. – Maddey Dec 29 '15 at 07:41
  • Use this tutorial.... after completing this tutorial you will never stuck in any view related issue http://www.raywenderlich.com/115440/auto-layout-tutorial-in-ios-9-part-1-getting-started-2 – Divyanshu Sharma Dec 29 '15 at 07:44
  • That tutorial only i followed to add constraints for all uiview – Maddey Dec 29 '15 at 07:46
1

View 1

View1

View 2

View2

you can do it by adding contraints like this also

Rahul Patel
  • 1,822
  • 12
  • 21