Search code examples
iphoneiosios7

Setting shadowImage On Translucent Navigation Bar


I am trying to set the shadowImage of the navigaion bar in my app delegate:

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

This does not work by itself. It only works if I set the background image of the navigaion bar as well:

[[UINavigationBar appearance]setBackgroundImage:[UIImage new]forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];

Here is my problem... the navigation bar is transluncent and I would like to keep it that way (no background images). But it seems that I cant set the shadowImage without setting the background image.

How can I set the shadowImage on translucent navigation bar?

Thanks!


Solution

  • Yes, you cannot set a shadowImage of a navigationBar without setting its backgroundImage :

    See UINavigationBar Documentation :

    For a custom shadow image to be shown, a custom background image must also be set with the setBackgroundImage:forBarMetrics: method.

    But you can render shadowImage invisible with empty image :

    [[UINavigationBar appearance] setShadowImage:[[UIImage alloc ]init]];