问题描述
我遇到了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 $ c $的左侧c>是距离
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中心两个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!