【发布时间】:2013-05-19 20:29:27
【问题描述】:
像CGRectMake(),但它指定中心,水平和垂直?
【问题讨论】:
-
您希望框架与超级视图大小相同,然后居中? stackoverflow.com/questions/1054558/…
标签: ios objective-c uiview uilabel
像CGRectMake(),但它指定中心,水平和垂直?
【问题讨论】:
标签: ios objective-c uiview uilabel
【讨论】:
你也可以label.center = [superview convertPoint:superview.center fromView:superview.superview];=P
【讨论】:
将标签的center 属性设置为其父视图bounds 的中心点。由于 superview 的 center 和 frame 属性位于 它们的 superview 的坐标空间中,因此这些属性没有帮助(除非您像 fumoboy 那样进行转换)。
label.center = CGRectGetMidPoint(label.superview.bounds);
为了方便,我做了这个函数:
CGPoint CGRectGetMidPoint(CGRect rect)
{
return CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
}
【讨论】: