0
votes

I have an application in which their is a screen. Which contains some UIView inside UIView.

Now the height of UIView(Parent) is Dynamic. It is adjusting according to Screen Height.

I have placed my UIView(child) inside it.

My UIView (parent) without Constraints.

Now,

I have added Following COnstraints:

Constraint to Parent View

Top , Bottom , Leading , Trailing

Constraint added to SubViews

UIView-1 : leading , trailing , top , height

UIView-2 : leading , trailing , vertical spacing (UIView 1) , height

UIView-3 : leading , trailing , vertical spacing (UIView 2) , height

UIView-4 : leading , trailing , vertical spacing (UIView 3) , height

Now I am getting this Screen:

enter image description here

When I change UIView 4 Constraint to :

UIView-4 : leading , trailing , vertical spacing (UIView 3) , height , Bottom

I am getting this screen:

enter image description here

My Parent view shrinks from 340 to 217 .

But I want to manage the vertical spacing between the views to increase or decrease. What Constraint I am missing.

Edit

I have changed the xib size to 3.5 inch and then to freeform. Now I have this much of space. How can I add spacer views?

enter image description here

2
you should give equal height constraint to all of your subviews! Also if you want to have more control for vertical space use blank views as spacers in between those views! And give equal height constraint to the all spacer views and after that select all white subviews and give equal height constraint! - Teja Nandamuri
Should I remove the Height constraint and apply equal height ? @TejaNandamuri - Dalvik
yes. PLs check my updated commment! @RahulMishra - Teja Nandamuri
@TejaNandamuri yes Thanks I am trying that...and Please see my updated question - Dalvik
you should add the spacer view between the two white views/ or wherevr you see pink gap and give the spacer view background color as clear color, to make sure your spacing works give it a different color so that you can differtentiate easily, and later you can change it to clear color@RahulMishra - Teja Nandamuri

2 Answers

0
votes

You should be using UIStackView for this type of layout.

Or, if you want to keep compatibility with iOS7&8 you should use spacer views. That means that you have to add some dummy views in the empty space between your views and set equal height constraints between all of them.

0
votes
  1. Use free form layout
  2. Arrange the views in the format

    enter image description here

  3. once you done arranging the layout

  4. select all red views, and give all 4 constraints, and additonally give equal height constraint
  5. now select all green spacer views and give all 4 constraints (top,leading,trail,bottom) and additionally give equal height constraint

  6. Create a property or outlet for the green spacer view height constraint, and you can change it to increase or decrease the red views height!