Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS auto-layout misplaced views off-by-one bug

Tags:

ios

autolayout

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?

like image 553
Matt Avatar asked Nov 10 '22 04:11

Matt


1 Answers

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.

like image 120
Eichhörnchen Avatar answered Nov 15 '22 12:11

Eichhörnchen