1
votes

I have this piece of code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    if([[UINavigationBar class] respondsToSelector:@selector(appearance)]
    {
        [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"bar-mid.png"] forBarMetrics:UIBarMetricsDefault];
    }
    //[[UINavigationBar appearance] setTintColor:[UIColor redColor]];
    return YES;
}

It works If I try to set the TintColor to red (in the commented line of code), but If i try to set a background image it doesn't work! Yes, I have the "bar-mid.png" image in "Supporting Files > Images". I use storyboard. This is the result:

enter image description here

Can you help me? Thanks!

2
Have you checked that it is being called within the "if" statement?Ōkami
Presumably you've also tried using bar-mid.png elsewhere in the app just to rule that out?Ōkami

2 Answers

1
votes

I can't understand why, but I changed the name of the two images in "greenNavigation.png" and "[email protected]" , I changed [UIImage imageNamed:@"bar-mid.png"] in [UIImage imageNamed:@"greenNavigation.png"] and now it works. Someone know why?

0
votes

Sometimes it happens to me as well. i delete image from xcode with "remove from hard disk" option. save for web from photoshop again. copy to xcode with "copy image to solution folder" option. then voila. it works. i know, not much of an explanation but it works sometimes. maybe it does not like image encoding or something.