Set the center of a UIButton programmatically - SWIFT

后端 未结 5 1496
孤街浪徒
孤街浪徒 2021-02-19 11:22

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 UIBut

5条回答
  •  日久生厌
    2021-02-19 11:41

    Try .center property like

    myButton.center = self.view.center
    

    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
    

提交回复
热议问题