本文介绍了以编程方式设置UIButton的中心 - SWIFT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 UIView
中有一个 UIButton
,我的 UIButton
我在故事板中设置了约束。现在,我想在 UIView
的中心设置 UIButton
的中心。我将如何以编程方式执行此操作?
I have a UIButton
inside a UIView
, my UIButton
has constraints which I set in storyboard. Now, I want to set the center of the UIButton
at the center of the UIView
. How will I do that programmatically?
推荐答案
尝试 .center
属性如:
myButton.center = self.view.center
您还可以指定 x
和 y
如果需要。
You can also specify x
and y
If you need.
myButton.center.x = self.view.center.x // for horizontal
myButton.center.y = self.view.center.y // for vertical
这篇关于以编程方式设置UIButton的中心 - SWIFT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!