简体   繁体   中英

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.

  • 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:

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

  • 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

在此处输入图片说明

Rest of buttons are aligned with Button1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM