如何获取UI按钮iPhone的X和Y位置 [英] How to get the X and Y position of a UI button iPhone

查看:113
本文介绍了如何获取UI按钮iPhone的X和Y位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何在可可中获取UIButton的x和y位置吗?

Could somebody show me how to get the x and y position of a UIButton in cocoa?

单击时按钮在屏幕上移动并且我想使用它当前位置相对于它定位另一个UIBUtton。

The button moves on the screen when clicked and I want to use it's current position to position another UIBUtton relative to it.

我尝试过使用

CGRect rect=[myButton imageRectForContentRect];

编译器告诉我myButton可能无法响应imageRectForContentRect。

The compiler tells me that myButton may not respond to imageRectForContentRect.

推荐答案

使用

myButton.frame

特别是对于位置,请使用myButton.frame.origin.x和myButton.frame.origin.y。这将是左上角。

Specifically for position, use myButton.frame.origin.x and myButton.frame.origin.y. That would be the top left corner.

这篇关于如何获取UI按钮iPhone的X和Y位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆