I styled a UIBarButtonItem
using Appearance API like the following
[[UIBarButtonItem appearance] setBackgroundImage:barButtonBgImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
This works great all over the app. The problem is, that this also changes the buttons in video views of YouTube videos that get loaded if you click a YouTube video in a uiwebview
.
adding code like this:
[[UIBarButtonItem appearanceWhenContainedIn:[MPMoviePlayerViewController class], nil] setBackgroundImage:barButtonBgImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
doesn't change anything (because it seems the YouTube thing isn't just a MPMoviePlayerViewController
.
If I understand correctly, I am also not allowed to change the buttons of the YouTube view (and also I don't want this).
Any ideas how I could stop setting custom bar button images on this YouTube video view?
Here is the sample project if you want to take a closer look: https://dl.dropbox.com/u/80699/BarItemsSample.zip
Because you are misunderstanding what dose appearanceWhenContainedIn: do.
The SDK document said:
To customize the appearances for instances of a class when contained within an instance of a container class, or instances in a hierarchy, you use appearanceWhenContainedIn: to get the appearance proxy for the class.
The code below dose what you are requiring in you question. Try it before you question me please.
For iOS 5.x, you should make a subclass of UINavigationBar (no any override needed), for example
//In MJAppDelegate.h:
@interface MyNavigationBar : UINavigationBar
@end
//In MJAppDelegate.m:
@implementation MyNavigationBar
@end
Then you should edit your storyboard, let it use MyNavigationBar as its UINavigationController's navigation bar.
Finally, you can use the code below to get what you want:
[[UIBarButtonItem appearanceWhenContainedIn:[MyNavigationBar class], nil] setBackgroundImage:barButtonBgImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
For iOS 6, you can just use the code below:
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], [UINavigationController class], nil] setBackgroundImage:barButtonBgImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
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