Evgeniy Kleban
Evgeniy Kleban

Reputation: 6940

Origin position of UIBarButtons

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?

Upvotes: 0

Views: 59

Answers (2)

Mohamad Bachir Sidani
Mohamad Bachir Sidani

Reputation: 2099

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]

Upvotes: 0

Cy-4AH
Cy-4AH

Reputation: 4585

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.

Upvotes: 1

Related Questions