Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NavigationBar setShadowImage not always working

I'm trying to set a custom shadow image for the navigation bar in my table views, but it's only showing in some views. I've created a super class to set the styles for my table views.

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Set navigation bar background
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbarbackground.png"] forBarMetrics:UIBarMetricsDefault];

    // Set navigation bar shadow imag
    [self.navigationController.navigationBar setShadowImage:[UIImage imageNamed:@"navigationbarshadow.png"]];

In the view I see at starting my app, no shadow is showed. But when I touch the [+] button in my navigation bar to open my 'add new item' table view, it does show a shadow.

Could someone point me in the right direction here?

like image 699
lsdevries Avatar asked Feb 01 '13 10:02

lsdevries


2 Answers

you need to set custom backgroudImage for UINavigationBar, then the shadowImage can work.

like image 194
MoLice Avatar answered Sep 28 '22 18:09

MoLice


The Appearance proxy should work.

Just call it somewhere (e.g. in your AppDelegate) upon startup.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ 
    [self customizeAppearance];
    return YES;
}

- (void) customizeAppearance 
{
    // Set the background image for *all* UINavigationBars
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navigationbarbackground"] forBarMetrics:UIBarMetricsDefault];

    // Set the shadow image for *all* UINavigationBars
    [[UINavigationBar appearance] setShadowImage:[UIImage imageNamed:@"navigationbarshadow.png"]];  

    //add other appearance stuff here...
}

However if you create a storyboard with multiple UINavigationController's in it and a bunch of segue's pushing navigation controller's you might get a corrupt view controller structure which might be the problem here.

Another possible issue might be the Clip Subviews option of a Navigation Bar somewhere in your nib file or you storyboard. Make sure it is turned off if you want the shadow (image)!

ClipSubviews

By the way, if you use imageNamed you don't need to include the file extension.

like image 27
Tieme Avatar answered Sep 25 '22 18:09

Tieme