Reputation: 571
I'm using auto layout in Xcode and I have some buttons I want to be near the center, but not on it. I know I can use alignment constraints to be exactly in the center, in this menu:
However, I want to not be exactly in the center, lets say 50 pixels up and to the right. How can I do this? I'm sure it's an easy thing to do, but I can't seem to find anything elsewhere on the web.
Upvotes: 0
Views: 285
Reputation: 610
If you want the center of your button to be 50 points up and to the right of the parent view's center you can use a center x alignment constraint and a center y alignment constraint and set the center x alignment constraint's constant to 50 and the center y alignment constraint's constant to -50.
Upvotes: 2
Reputation: 59496
Create a view with size 50 * 50. Then place this view exactly at the center using auto layout.
Next you need to place your button using vertical space
and horizontal space
in order to be aligned to the upper right corner of the view.
Finally make the view transparent.
Upvotes: 0