Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appearance proxy - setShadowImage alternative for iOS 5?

Hello I'm using this code to set the shadow image of my navbar:

if ([self.navigationController.navigationBar respondsToSelector:@selector(shadowImage)]) {

    [[UINavigationBar appearance] setShadowImage:[UIImage imageNamed:@"nav-bar-shadow"]];

    [[UIToolbar appearance] setShadowImage:[UIImage imageNamed:@"tool-bar-shadow"]  forToolbarPosition:UIToolbarPositionAny];
}

However it seems this is iOS 6 only (though I can't say for sure - I can't find documentation about this anywhere). It doesn't work on iOS 5.

Is there some kind of alternative - globally setting an image under the navbar? I thought of custom UIView, but how to do this globally?

like image 796
Devfly Avatar asked Nov 13 '22 21:11

Devfly


1 Answers

You can:

  1. Add a subview containing the shadow image to your viewController.view
  2. Add a subview containing the shadow image to your [[UIApplication sharedApplication] keyWindow], which will add the image globally on your window. However, it can get a little bit ugly e.g. when displaying a modal view controller.
  3. You can subclass UINavigationBar, do some magic with subviews in there and then initialize your navigationController via [[UINavigationController alloc] initWithNavigationBarClass:[YourNavBarSubclass class] toolbarClass:[UIToolbar class]]
like image 182
akashivskyy Avatar answered Nov 15 '22 12:11

akashivskyy