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

前端 未结 6 1677

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 should do it:

    yourButton.frame = CGRectMake(self.view.frame.size.width/2 - yourButton.frame.size.width/2, self.view.frame.size.height/2 - yourButton.frame.size.height/2, yourButton.frame.size.width, yourButton.frame.size.height);
    

提交回复
热议问题