1

I have a collectionviewcell with a button and a label like this:

enter image description here

The button is a 100x100 square, the label is a 100x40 rectangle. The cell is adjusted to 120x140.

So the constraints I have added are:

Button:

  • aspect ratio 1:1
  • top to superview space 0
  • bottom to label space 0
  • center horizontally in respect with cell
  • width = 100

LABEL

  • same width as button
  • center horizontally in respect to button
  • height 40
  • top space to button 0
  • bottom space to cell 0

I see constrain errors everywhere.

I have tried to embed these two views on a stack. It craps everything.

Then I have tried to embed the stack into a view, same problem.

This defies any logic.

Can you guys tell me how in the name of heaven I constrain these elements? All I want is both elements centered horizontally, the button on top, the label on the bottom, both with the same width of 100, the button squared and the label with a hight of 40. Both in a cell of 120x140.

Thanks

Duck
  • 32,792
  • 46
  • 221
  • 426

1 Answers1

0

This is how you should set your constraints using a stack view in a cell to accomplish what you need: (cell width = 120, height = 140)

enter image description here

giorashc
  • 13,502
  • 3
  • 32
  • 69
  • not working for me. My stack moved to x,y = -22, -70. The stack is embedded on a view that is constrained 0,0,0,0 to the cell but the cell have these coordinates (0,0,56,0). I had to add a width of 100 to the label. Things inside the stack appear to be right. – Duck Jan 11 '19 at 18:56
  • the stack is adjusted to vertical, leading, fill, 0... is that correct? – Duck Jan 11 '19 at 18:58
  • yes the stack should cover the view it is contained in.. when you say your stack view moved.. did you click the Update Frames button at the right bottom of the storyboard screen? and sometimes after editing a cell in storyboard it is not updated correctly until you close and open the storyboard file again – giorashc Jan 12 '19 at 08:26