从UIButton获取中心位置

4
我需要获取UIButton原始中心的位置。
例如,这将给出UIButton的大小。
  NSLog(@"%f",button.frame.origin.x);
  NSLog(@"%f",button.frame.origin.y);

如何获取UIButton原点框架的中心位置?任何帮助都将不胜感激。
2个回答

8
 CGPoint centerPoint = [button center];

除了您的NSLog注释外,NSLog(@“%f,%f”,centerPoint.x,centerPoint.y)也可以使用。 - slysid

2
NSLog(@"%f",button.frame.origin.x);
NSLog(@"%f",button.frame.origin.y);

不,这不会给你按钮的大小,它将给出您的按钮的 x 和 y 位置,按钮大小是:
NSLog(@"%f",button.frame.size.width);
NSLog(@"%f",button.frame.size.height);

你可以这样获取按钮的中心位置:

CGPoint center = [button center];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接