The Broken Ace
The Broken Ace

Reputation: 51

How to change center of object?

This is the code I'm using to center my button to the bottom of the screen:

CGFloat centro = self.view.center.x;
CGFloat bottom = CGRectGetMaxY(self.view.frame);

_sendButton.center = CGPointMake(centro, bottom);

However, the actual center of the button is set to be at the bottom of the screen, which covers half the button. How can I set it so that the very lowest point on the button is set to:

CGPointMake(centro,bottom)

instead?

Upvotes: 0

Views: 152

Answers (1)

rmaddy
rmaddy

Reputation: 318824

You need to subtract half the height of the button:

CGFloat centro = self.view.center.x;
CGFloat bottom = CGRectGetMaxY(self.view.frame) - _sendButton.frame.size.height / 2.0;

_sendButton.center = CGPointMake(centro, bottom);

Upvotes: 2

Related Questions