使用Cocoa Auto Layout中心两个按钮 [英] Centering two buttons with Cocoa Auto Layout

查看:87
本文介绍了使用Cocoa Auto Layout中心两个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了Cocoa Auto Layout的问题,无法解决这个问题。
我想要实现的是让两个按钮始终位于视图中心,如下所示。

I have a problem with Cocoa Auto Layout and can't get my head around this problem. All I'd like to achieve is to have two buttons always centered in a view as depicted below.

我尝试了很多不同的方法但没有成功:(请帮助我在这里。

I've tried lots of different approaches without any success :( please help me out here.

推荐答案

这样做的另一个技巧是对齐按钮的右侧是距离 superview 中心空间大小的一半,以及 button2 是距离 superview 中心空间大小的一半。

Another trick to do this is to align the right side of button to be half the size of the space away from the Center of superview, and the left side of button2 to be half the size of the space away from the Center of superview.

这只有在你有一个超级视图,只围绕你想要居中的两个视图。

This only really works if you have a superview that only surrounds the two views you want to centre though.

这篇关于使用Cocoa Auto Layout中心两个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆