iOS SDK: Moving the button into the center of screen by code

前端 未结 6 1714

I want to move a button to the center of the screen by code. I saw somewhere it is just few lines of code, but could not find them.

6条回答
  •  既然无缘
    2021-01-05 01:47

    This centers the button in its superview:

    CGRect bounds = button.superview.bounds;
    button.center = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
    

提交回复
热议问题