0
点赞
收藏
分享

微信扫一扫

[IOS]通过center point创建UIView


1.只需要任意创建一个view,然后改变该view的center值就可以了,该view会移位至中心点


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.有关中心点的一些补充

    1.页面的中心点:self.view.center

​CGRectGetMidX​​ and ​​CGRectGetMidY​

 

3.有时候会出现,通过center直接赋值不能出现在预期的位置情况:

例如btn.center = view.center,会发现移位了

此时应该手动获得view的中心点,如下:



wifiBtn.center = CGPointMake(CGRectGetMidX(_wifi_view.bounds), CGRectGetMidY(_wifi_view.bounds));



 

参考:

1.https://stackoverflow.com/questions/18189572/cgrect-positioning-according-to-center-point

举报

相关推荐

0 条评论