Search code examples
iosobjective-ccgpoint

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?


Solution

  • 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);