I believe that I came up with the most effective solution currently available for this problem. Unfortunately, the Youtube video player has a private class called MPInlineVideoViewController . It is not possible to use an appearance proxy in this class, which in any case will be a hack.
Here is what I came up with. I encoded it so that it could be used in more than one place, and also could be used to solve other problems of the Appearance proxy, such as the reverse and the next UIBarButtonItems when filling out the form in UIWebView.
AppDelegate.h
extern NSString * const ToggleAppearanceStyles;
AppDelegate.m
NSString * const ToggleAppearanceStyles = @"ToggleAppearanceStyles"; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSNotification *note = [NSNotification notificationWithName:ToggleAppearanceStyles object:NULL userInfo:@{@"flag" : @(YES)}]; [self toggleAppearanceStyles:note]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(toggleAppearanceStyles:) name:ToggleAppearanceStyles object:NULL]; return YES; } -(void)toggleAppearanceStyles:(NSNotification *)note { UIImage *barButtonBgImage = nil; UIImage *barButtonBgImageActive = nil; if([note.userInfo[@"flag"] boolValue]) { barButtonBgImage = [[UIImage imageNamed:@"g_barbutton.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(15, 4, 15, 4)]; barButtonBgImageActive = [[UIImage imageNamed:@"g_barbutton_active.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(15, 4, 15, 4)]; } [[UIBarButtonItem appearance] setBackgroundImage:barButtonBgImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; [[UIBarButtonItem appearance] setBackgroundImage:barButtonBgImageActive forState:UIControlStateSelected barMetrics:UIBarMetricsDefault]; }
MJWebViewController.m
-(void)viewDidAppear:(BOOL)animated { [[NSNotificationCenter defaultCenter] postNotificationName:ToggleAppearanceStyles object:NULL userInfo:@{@"flag" : @(NO)}]; [super viewDidAppear:animated]; } -(void)viewWillDisappear:(BOOL)animated { [[NSNotificationCenter defaultCenter] postNotificationName:ToggleAppearanceStyles object:NULL userInfo:@{@"flag" : @(YES)}]; [super viewWillDisappear:animated]; }
In the above code, we switch the appearance styles to the default values, so when the YouTube player loads, it uses the default styles. The current ViewController is already loaded, so it will have a style.
When the YouTube player deviates, the current ViewController will not restart, thereby preserving the style. When the current ViewController disappears, the styles that appear are turned back on.
brynbodayle
source share