Since UIBarButtonItem
doesn't subclass UIView
, it's impossible to get at the normal characteristics like its frame
.
One way to do this is [barButtonItem valueForKey:@"view"]
This works perfectly, and allows you to add a GestureRecognizer (for instance) to the underlying UIView
.
However, is this a private UIKit
API violation?
This is not private in terms of immediate rejection upon validation, but it's private enough to be considered fragile (that is, new iOS version can break your existing app in the app store that's using the code).
I can say, that a similar code (fetching backgroundView ivar of UIToolbar via KVC) has passed app store validation and is being used in production.
In case of possible bad things, you must wrap the method in @try { ... } @catch
, so that you intercept KVC possibly failing in newer iOS release.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With