Fustigador
Fustigador

Reputation: 6469

Put items around center of the screen in iOS

I need to put some buttons around the vertical center of the screen. As far as I know, there is no explicit way to achieve that, so I have thought putting a label, or something, hidden, and align the buttons using that label as a reference.

But, I am not sure if that is an acceptable way to do so.

Is there a way to do it without being "hacky"? Can I achieve my goal with some way I am not aware of? Or simply the hacky way is acceptable?

Thank you.

PS: Need to do it in auto layout, not programmatically.

Upvotes: 0

Views: 79

Answers (1)

Irfan
Irfan

Reputation: 5130

  • Placing a reference view at center and then attaching button to that view is not a good way I guess. Because when we make that reference hidden then the next person will never no the constraints...
  • I mostly use center of button equal to center of screen with some proportion:

I tried four buttons to make them around vertical center

The result on different screen is shown in pictures:

enter image description here

enter image description here

enter image description here

  • Constraints on Button1 is as follow
  • Align Center Y to : Superview (center Y of Button1 is 75% center Y of superview)
  • Align Center X to : Superview (center X of Button1 is 75% center X of superview)
  • Then width and height constraint to Button1

enter image description here

Rest of buttons are aligned with Button1

Upvotes: 1

Related Questions