从NIB获取UIButton实例(无交互)

发布于 2024-12-23 04:49:22 字数 162 浏览 6 评论 0原文

我想知道如何获取 UIButton 的实例而不与其交互。我在我的 xib 中放置了一个按钮,只想能够获取它在代码中的位置。我创建了一个 IBOutlet 并将它们链接起来,但是当我查看 IBOutlet 的位置时,它被设置为 0,0。

非常感谢任何帮助。

亲切的问候, 埃利奥特

I was wondering how to grab an instance of a UIButton without interacting with it. I have placed a button in my xib, and just want to be able to get it's position in code. I have created an IBOutlet and linked them up, but when I look at the position of the IBOutlet it is set to 0,0.

Any help is much appreciated.

Kind Regards,
Elliott

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千鲤 2024-12-30 04:49:22

您必须设置该按钮的 tag 属性,例如 1001,例如在 viewDidLoad 方法中,您可以通过以下方式获取该按钮:

- (void) viewDidLoad
  {
      UIButton *temp = (UIButton *)[self.view viewWithTag:1001];
      NSLog(@"%f",temp.frame.origin.x);
      NSLog(@"%f",temp.frame.origin.y);
  }

希望它可以帮助您...

you have to set tag property of that but button, say 1001, and for example in viewDidLoad method you can get that button by :

- (void) viewDidLoad
  {
      UIButton *temp = (UIButton *)[self.view viewWithTag:1001];
      NSLog(@"%f",temp.frame.origin.x);
      NSLog(@"%f",temp.frame.origin.y);
  }

Hope it helps you...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文