UIBarButtonItem
does not extend UIView
, so there is nothing like a frame property.
But is there any way I can get what is it\'s CGRec
As long as UIBarButtonItem
(and UITabBarItem
) does not inherit from UIView
—for historical reasons UIBarItem
inherits from NSObject
—this craziness continues (as of this writing, iOS 8.2 and counting ... )
The best answer in this thread is obviously @KennyTM's. Don't be silly and use the private API to find the view.
Here's a oneline Swift solution to get an origin.x
sorted array (like Kenny's answer suggests):
let buttonFrames = myToolbar.subviews.filter({
$0 is UIControl
}).sorted({
$0.frame.origin.x < $1.frame.origin.x
}).map({
$0.convertRect($0.bounds, toView:nil)
})
The array is now origin.x
sorted with the UIBarButtonItem
frames.
(If you feel the need to read more about other people's struggles with UIBarButtonItem, I recommend Ash Furrow's blog post from 2012: Exploring UIBarButtonItem)