Search code examples
iosobjective-cuibuttonposition

Moving UIButton on Y Axis


I have a few UIButtons in my project, however I'd like to be able to move their position on the Y axis through code. And also, would moving the button trough code affect the auto layout / universal storyboard placement?

Thanks :)


Solution

  • If you are using autolayout, remove the constraints before applying a new frame to the button:

    [button removeConstraints:button.constraints];
    [button setTranslatesAutoresizingMaskIntoConstraints:NO];
    button.frame = CGRectMake(button.frame.origin.x, button.frame.origin.y + deltaY, button.frame.size.width, button.frame.size.height);