Renato Probst
Renato Probst

Reputation: 6054

How to make a grid side to side uiview responsive on storyboard using auto layout

im trying to make a month calendar in swift, but im strugging with an auto layout issue.

I need 7 squares side to side, and i want to make them responsive. I have tryied to set every square trailling and leading based on the preview and next square, but it wont work without setting the width (what will make it go unresponsive). Can someone help me please?

Storyboard

Upvotes: 0

Views: 596

Answers (1)

BaseZen
BaseZen

Reputation: 8718

If you know there's always 7 cells in a row (sounds like it, calendars are pretty stable that way), you want to set up a width relationship.

  1. Set the width of the first cell to the width of the parent view ("Equal Widths"). Sounds strange at first

  2. But then double-click on the resulting constraint in the Constraints Inspector to get the detailed constraint editor.

  3. Set the Multiplier to "1:7"

  4. Set the Constant to some small value to allow for inter-cell padding.

  5. Set all the other cells to equal the width of the first cell.

Upvotes: 2

Related Questions