Get the width of a UIBarButtonItem

Fabio Poloni picture Fabio Poloni · Feb 21, 2011 · Viewed 18.5k times · Source

I'm trying to get the width of a UIBarButtonItem.

This doesn't work:

barbuttonitem.customView.frame.size.width

And this won't work, either:

barbuttonitem.width

Answer

Jeremy W. Sherman picture Jeremy W. Sherman · Feb 21, 2011

What about this:

UIBarButtonItem *item = /*...*/;
UIView *view = [item valueForKey:@"view"];
CGFloat width = view? [view frame].size.width : (CGFloat)0.0;