How to determine position of UIBarButtonItem in UIToolbar?

Hisham picture Hisham · Nov 22, 2011 · Viewed 15.9k times · Source

What's the easiest way to determine the x,y location of a UIBarButtonItem in a UIToolbar?

The only answer I found is in any way to know where uibarbuttonitem has been drawn.

All proposed answers seem too complicated. There ought to be a simpler way to get the position of the damn UIBarButtonItem isn't there?

Answer

johosher picture johosher · May 3, 2013

I used this which seems to be the most elegant way

- (CGRect)frameForBarButtonItem:(UIBarButtonItem *)buttonItem
{
    UIView *view = [buttonItem valueForKey:@"view"];
    return  view ? view.frame : CGRectZero;
}