3

I have two views in a view and i have a requirement to increase the distance between those views in aspect ratio to the main view. I am using auto layout.

Thanks in advance.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
sourav
  • 779
  • 5
  • 14
  • did you set vertical spacing constraint between them ? – Mo Farhand Jan 25 '16 at 06:23
  • any image attachments? – iamalizade Jan 25 '16 at 06:26
  • yes i have set vertical spacing .but i want that space in aspect ratio. – sourav Jan 25 '16 at 06:39
  • maybe you can find something helpful here : http://stackoverflow.com/questions/13075415/evenly-space-multiple-views-within-a-container-view . I think you just need to set the bottom spacing and then adjust the multiplier according to your need. – user3752049 Jan 25 '16 at 06:43
  • add 1 more view(with clear color so its not seen or set hidden) ex : view3 between those two views Ex: View1, View2. set constraint with Two Views (View1, view2) .i. e. View3 top to view1 bottom (if it's above view2 & view 3) & View3 Bottom to view2 bottom (if it's below view2 & view 1) . Now set equal Hight Of view3 (new Separator View) to main view and set Multiplier as per requirement – Bhargav B. Bajani Jan 25 '16 at 06:59
  • @sourav, let me know if my answer helps your situation. – Unis Barakat Jan 25 '16 at 09:06
  • @UnisBarakat I tried that but it did not match my requirement . – sourav Jan 25 '16 at 09:50
  • @sourav, I've updated the answer. Hope it works out with this other method. (This is the most I can do given that you didn't share any details in the project with us much. If you are willing to share files I can perhaps do this for you and send you a link.) – Unis Barakat Jan 25 '16 at 10:06
  • @sourav, you might want to check out http://stackoverflow.com/questions/13075415/evenly-space-multiple-views-within-a-container-view – Unis Barakat Jan 25 '16 at 12:31
  • @UnisBarakat thats i know .But that is not the question i have asked dear . – sourav Jan 25 '16 at 12:58

2 Answers2

1

One way to solve your problem is -

  1. For your upper view give top space constraint with super view and other required constraint.

  2. For your lower view give bottom space constraint with super view and other required constraints.

You don't really need to give vertical space because your views will be pinned with fixed space with top and bottom of super view, so if screen size will grow space between your views will automatically grow.

Important to note however: You must add the height constraint for both views and have either fixed width constraint or have Leading and trailing space constraints.

See ScreenShot

enter image description here

Ajay Kumar
  • 1,807
  • 18
  • 27
1

Since you have more than one view, I recommend doing the following assuming this is the result you are looking for:

enter image description here

STEP 1 : select all your views

Step 2 : go to Editor -> Embed In -> Stack View (now it will group them together) I'm assuming that you set the width and height constraint for each of your views before doing this.

Step 3 : once you have done that select the stack (not the individual views). but rather the entire stack (I would do this from the side menu) and set the top layout and the bottom layout.

step 4 : Go here and make these settings for the stack as you have it selected

final step

and that should do it. Let me know if I should clarify anything.

UPDATE:

If you do not want equal spacing, you can still use the above method by playing around with different stacks, etc.. However, There is a method I've used in the past to get this, which is setting a multiplier instead of a number for say spacing between bottom layout and view. Here is an example that might help below:

enter image description here

you can play around with it to get your desired results.

Unis Barakat
  • 876
  • 1
  • 8
  • 23
  • @sourav best of luck – Unis Barakat Jan 25 '16 at 09:35
  • You have shown for equal spacing between views . Thats not my requirement dear .Let us assume the space between the view 1 and view 2 in iphone 5 is 40 and the same between 2 and 3 is 20 ,In iPhone 6 it should be 46.97 and 23.48 . and those view should also increase in aspect ratio . – sourav Jan 25 '16 at 09:43