1

I just started adding UIAppearance to my project and got stuck with UIBarButtonItems:

- (void)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]} forState:UIControlStateNormal];
    [[UIBarButtonItem appearance] setBackButtonBackgroundImage:[[UIImage imageNamed:@"UIBarButtonItemBack"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 2, 0, 13)] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[JWViewController alloc] initWithNibNam:@"JWViewcontroller" bundle:nil]];
    [self.window makeKeyAndVisible];
    return YES;
}

When I open up the app and click a tableViewCell, the navigationController pushes into another viewController and presents a back button with white text color and no background image. When I push the button, the background image appears and when I then cancel the touch, it is there. When I actually go back and then into the second view again, it also appears.

Is this a known issue on iOS 7 or can you imagine any fix for it?

Julian F. Weinert
  • 7,474
  • 7
  • 59
  • 107
  • Known issue; see [iOS 7 custom back button](http://stackoverflow.com/questions/18824887/ios-7-custom-back-button). One option is to ditch the background images (which is more iOS7-ish anyways), or there is a patch at that link which you could use to fix it. – Carl Lindberg Dec 29 '13 at 06:55

1 Answers1

0

Same problem here. Seems that calling setNeedsDisplay explicitly does the trick.

I added these lines to viewWillAppear/viewDidLoad (etc) of the view controller I needed to fix:

dispatch_async(dispatch_get_main_queue(), ^{
    [[self.navigationController.navigationBar subviews] makeObjectsPerformSelector:@selector(setNeedsDisplay)];
});
ashabtay
  • 86
  • 1
  • 3