【发布时间】:2011-05-21 23:01:30
【问题描述】:
我想以编程方式获取 UILabel 的位置。我该怎么做,即获取 UILabel 的 x 和 y?
我试过textAlert.center.y或textAlert.center.x(textalert是UILabel的名字)。
【问题讨论】:
-
名字是
textalert还是textAlert?
标签: objective-c cocoa-touch ios4
我想以编程方式获取 UILabel 的位置。我该怎么做,即获取 UILabel 的 x 和 y?
我试过textAlert.center.y或textAlert.center.x(textalert是UILabel的名字)。
【问题讨论】:
textalert还是textAlert?
标签: objective-c cocoa-touch ios4
这是您要查找的 frame 属性。试试看。
textAlert.frame.origin.x
textAlert.frame.origin.y
textAlert.frame.size.width
textAlert.frame.size.height
【讨论】:
这实际上取决于您想要查看的哪个部分的坐标。
frame.origin - 返回左上角center - 返回视图的中心CGRectGetMinX(frame) - 获取左边缘的 x 坐标。CGRectGetMinY(frame) - 获取 y 坐标上边缘的坐标。CGRectGetMidX(frame) - 获取中心的 x 坐标。CGRectGetMidY(frame) - 获取中心的 y 坐标。CGRectGetMaxX(frame) - 获取右边缘的 x 坐标。CGRectGetMaxY(frame) - 获取底部边缘的 y 坐标。
【讨论】: