Set the center of a UIButton programmatically - SWIFT

后端 未结 5 1508
孤街浪徒
孤街浪徒 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:33

    This can be done in 2 ways:

    • myButton.center = view.center //view is your parentView

    • myButton.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true myButton.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true

提交回复
热议问题