0

enter image description here

I'hv 4 UIViews. All of them are in a parent UIView. The Parent has it's fixed height constraint which is 240. But I have to minimize it to 190 for iPhone 4.

enter image description here

The height of the child views are fixed. Now My question is how can I set all those 4 UIView in it's parent view with same Gap so that If I just change the height of It's parents view, child view could fit automatically with same Gap in it's parent View.

Thanks a lot in advance.

Parents View constraint :

Leading 0
Trailing 0
Top to it's Parents X
Bottom to it's Parents Y
Height 240 (which I have to decrease in iPhone 4)

Child View constraint :

Sign In with Facebook View Constraints:
Leading 0
Trailing 0
Top 0
Vertical fixed with the second below child view(I set it with a fixed value like <= X which doesn't work)

Sign In with Twitter View Constraints:
Leading 0
Trailing 0
Vertical fixed with the third below child view(I set it with a fixed value like <= X which doesn't work)

Sign In with phone View Constraints:
Leading 0
Trailing 0
Vertical fixed with the fourth below child view(I set it with a fixed value like <= X which doesn't work)

Sign In with email View Constraints:
Leading 0
Trailing 0
Bottom to it's parents 0

Tulon
  • 4,011
  • 6
  • 36
  • 56
  • You may use stackView; https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIStackView_Class_Reference/ – pkc456 Nov 16 '15 at 10:02
  • Thanks a lot for the suggestion, but unfortunately my deployment target is iOS 7.0. :( – Tulon Nov 16 '15 at 10:08
  • This will work for you then: http://stackoverflow.com/a/25898949/988169 – pkc456 Nov 16 '15 at 10:09
  • btw why do you need a Top constraint for twiiter, phone and email aren't you keeping a vertical space between the current view and it's top view. Just remove them and check it – harsha yarabarla Nov 16 '15 at 10:13
  • It was a mistake. I edited my post. Thanks. – Tulon Nov 16 '15 at 10:15

4 Answers4

3

Finally I found an alternative way to do it. The system is, put 3 extra UIView in each Gap. Like this.

enter image description here

Now named it like this:

1stSeperatorView
2ndSeperatorView
3rdSeperatorView

Clear all vertical constraints of ChildViews, except top one & bottom one. Now set seperator Views constraint like the below :

1stSeperatorView :
Leading 0
Trailing 0
vertical with it's top 0
vertical with it's bottom 0

2ndSeperatorView :
Leading 0
Trailing 0
vertical with it's bottom 0

3rdSeperatorView :
Leading 0
Trailing 0
vertical with it's bottom 0

Now the most important thing. Select 3 seperator view togather and set their Equal Height constrains from the Constraint Panel. Update Frame. Change the height of the Parents view as you want. It should be working perfectly.

Thanks a lot again to all, for your time. :)

Community
  • 1
  • 1
Tulon
  • 4,011
  • 6
  • 36
  • 56
2

First of all, in your case I'd use a UIButton, but let's discuss the solution...

Set in your storyboard the desired spacing between views. Try to find a space that works for both iPhone 4 and iPhone 5 sizes... Also remember iPhone 6!

Drag the 1st UIViewon the second while pressing CTRL and set a fixed "vertical spacing" constraint on all of them.

Do the same with 2nd to 3rd, 3rd to 4th, etc... They should keep the space in any screen size.

napolux
  • 15,574
  • 9
  • 51
  • 70
  • Actually, I do put UIButton in real project. For simple understanding I mention them as `UIView`. Any way I got the solution. Really appreciate your answer. Have a good day. :) – Tulon Nov 16 '15 at 10:46
2

Please check this URL: evenly-space-multiple-views-within-a-container-view

It will help you how to set view equally distant from each other without using spacer view.

Hope it helps in solving your problem.

Community
  • 1
  • 1
Dhaivat Vyas
  • 2,926
  • 1
  • 16
  • 26
1

Not sure it will help you or not but I think you should use UITableView instead of using 4 different view.You can set height of sections in GROUPED UITableView for same space.

bittu
  • 683
  • 7
  • 24