5
votes

I have two buttons which should take up half the width of the view, each.

I have:

  • leading-space constraint on the left-hand button to the superview
  • trailing-space constraint on the left-hand button to the right-hand button
  • trailing-space constraint on the right-hand button to the superview
  • equal-width constraint on the buttons

I get misplaced views:

Button 1 
  Expected: width=161 
  Actual: width=160

Button 2 
  Expected: width=161 
  Actual: width=160

I get the same with the vertical.

Surely, 320 / 2 = 160, right? Can anyone point out what I am doing wrong? Or should I just ignore the warnings?

2

2 Answers

1
votes

Misplaced views really seem to be more suggestions than requirements. Unless constraints are breaking, you probably have nothing to worry about.

If you want the warning to go away, try selecting "Update Constraints", as maybe they are missing an extra pixel in their addition to fill the screen.

0
votes

Are you doing this in a xib/storyboard? If you create the constraints by control-dragging between two views, they were probably created with their constant property set to whatever the offset of the views was at the time. Select each constraint and set its constant to 0 or whatever you want.