Reputation: 3968
Let's say i want to align a button (Delete) on the right border of every different device (3.5, 4, 4.5 inch etc.)
Should be very simple but, when i add a constraint to the right border:
New constraints are automatically added and i can see a dashed border rectangle on the top right of the view (which means that my button has been moved to the top.):
Why?? I don't need to add tons of contraints, i just want to align the button to the right and stay in the same position for every device.
Upvotes: 0
Views: 119
Reputation: 163
You added constraints for the x position of the button. Now you have to add constraints for the y position of the button. An easy way that will most of the time work is to go into the auto layout bar at the bottom and clicking the third icon from the left. Then you click either add missing constraints or reset to suggested constraints.
Upvotes: 1
Reputation: 443
You're seeing the red outline in the upper right corner because now that you've added one constraint Auto Layout needs additional constraints in order to know that you also want the button further down on the screen. You can accomplish this by also setting a constraint for position from the top, for instance.
Upvotes: 1
Reputation: 535547
Xcode is not "adding tons of constraints". It is doing what you said to do - and showing you that the results of doing that would be a disaster. It is telling you that you need to add more constraints or you'll have a mess on your hands.
Basically, as soon as you add one constraint to position/size an object, you must add sufficient constraints to position/size it unambiguously.
(Notice the warning/error messages in the document structure pane at the left, not shown in your screen shots. They are telling you something!)
Upvotes: 1