-2

Refreshing my self with Swift ... I want to center this button loginButton.center = self.view.center at the bottom of the view. The current code centers the button perfectly horizontally and vertically..

I have tried messing around with CGPoints and subView's but have had no luck.

mfaani
  • 33,269
  • 19
  • 164
  • 293

2 Answers2

1

Seems like you are not using Auto Layout. So this is what you are looking for:

button.center = CGPoint(x: view.bounds.width / 2,
                        y: view.bounds.height - button.bounds.height / 2)

If you want to use Auto Layout instead go with Sh_Khan's answer.

André Slotta
  • 13,774
  • 2
  • 22
  • 34
0
 let pos = CGPoint(x: self.view.bounds.midX, y: self.view.bounds.maxY - 80)
       loginButton.center = pos

       loginButton.translatesAutoresizingMaskIntoConstraints = false

       self.view.addSubview(loginButton)