-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.

3
  • can you post all the related code? Commented Sep 17, 2018 at 15:57
  • @Honey the only piece of code missing was this and thats it let loginButton:PPLoginButton = PPLoginButton.init() Commented Sep 17, 2018 at 16:03
  • @JoshuaPaulsen it's nice to say that the question title needs constraints instead of frame layout Commented Sep 17, 2018 at 18:38

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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)

2 Comments

You are mixing auto layout (loginButton.translatesAutoresizingMaskIntoConstraints = false) with setting frames manually (loginButton.center = pos) in this answer.
@AndréSlotta Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.