0

I have a somewhat complex layout that I want to make constraints for. This is it.

Top three all need to be equidistant from each other and equal widths and heights. Bottom three need to be equal width and heights, and also equidistant from each other.

How come Xcode doesn't have an equidistant margin option? I can't create a specific margin constraint because it wont look correct on smaller devices. Nothing I do seems to create acceptable constraints.

Thanks!

1
  • 3
    Put them in a UIStackView Commented Jul 12, 2016 at 19:28

2 Answers 2

1

For top three you need to create 5 additional views, place them between this three views and set that they should have the same width. One of them should have some constant width(than all other will get this width as well). Than bind them all by connecting leading and trealing constraints between them. Next thing to do, is to set your views width and height. Margin that you need will be that five views that you placed before between them.

The same thing you can do with your other views, just adding some views to make them as a margins.

Is it what you was searching for? If not Pls describe your problem and I will try to solve it.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm confused, what do I do with my 5th additional view? One would go on the left side of months, right side of months, right side of days, and right side of weeks. Where would the 5th go?
Woops, there need to be 4 views. My Mistake. Bit the main logic you got)
1

As @Dan said, UIStackView is your friend. Put the top three in a horizontal stack view and the bottom three in a vertical one. Your other alternatives are to fiddle with the Multiplier on individual constraints, i.e. 0.0 0.333, 0.667. That would require a lot of work. One other choice, if you're willing to wait to use this in Xcode 8, is that Apple has reinstated the old springs and struts style of pre-Autolayout in Xcode 8, and allows you to use that as an alternative, and/or mixed in with auto layout in Xcode 8. Try the UIStackview first, though, it's the path of least resistance.

1 Comment

I'm trying to follow this tutorial on UIStackView. When I put my top three in a stack and pin it (top: 12, left: 12, right: 12, bottom: 15), I get a constraint error for the top. I also have equal distance on, but the views wont distance themselves. Pic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.