1. Just create a view arbitrarily, and then change the center value of the view, the view will be shifted to the center point
UIButton* btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 70, 70)]; btn.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2);
2. Some supplements about the center point
1. The center point of the page: self.view.center
2. Get the coordinates of the center point of a view: CGRectGetMidX
and CGRectGetMidY
3. Sometimes it occurs that direct assignment through center cannot appear in the expected position:
For example, btn.center = view.center, you will find the shift
At this point, the center point of the view should be obtained manually, as follows:
wifiBtn.center = CGPointMake(CGRectGetMidX(_wifi_view.bounds), CGRectGetMidY(_wifi_view.bounds));
refer to:
1.https://stackoverflow.com/questions/18189572/cgrect-positioning-according-to-center-point