0

I need to know Y and X position of UIBarButtons and preferably its width and height.

I've tried with this solution: UIBarButtonItem: How can I find its frame? but it doesn't work for me.

I tried:

 UIBarButtonItem *item = _bbiPlus ;
 UIView *view = [item valueForKey:@"view"];

 NSLog(@"igrek? %f", view.frame.origin.y);

With output:

0.000.

How could i get position of item considering that it changes on different devices?

Community
  • 1
  • 1
Evgeniy Kleban
  • 6,794
  • 13
  • 54
  • 107

2 Answers2

1

You need use UIBarButtonItem with custom view, to have pointer at that view (valueForKey:@"view"] smells like private API: can be rejected, doesn't guarantee 100% result). You need use convertRect: functions to get coordinates in view relative to which you need coordinates.

Cy-4AH
  • 4,370
  • 2
  • 15
  • 22
0

try this

[self.view convertPoint:yourButton.origin toView:nil];

or in another words

[view.superview convertPoint:navButton.frame.origin toView:[UIApplication sharedApplication].keyWindow.rootViewController.view]
Mohamad Bachir Sidani
  • 2,077
  • 1
  • 11
  • 17