-1

I have implemented a customized navigation bar and toolbar in Xcode 4 targeting iOS 4.3 and now am updating my xcode 4.2 targeting iOS 5. In iOS 5 the customizations are not working, but whenever I use the iOS 4.3 simulator its working fine.

Thanks in advance

AlG
  • 14,697
  • 4
  • 41
  • 54
dj1
  • 1
  • 1
  • 7
  • The only answer that can be given to your question is : "Something is wrong". You haven't given enough information - what is your "customized navigation bar and toolbar" doing? What "customization things" are not working and how are they not working? Have you tried debugging setting breakpoints and stepping through your code? – Nick Bull Dec 20 '11 at 11:12
  • possible duplicate of [Navigation Bar customization in ios4 doesnt work in ios5](http://stackoverflow.com/questions/8255437/navigation-bar-customization-in-ios4-doesnt-work-in-ios5) – jrturton Dec 20 '11 at 11:13

1 Answers1

2

Are you customising the navigation bar using the drawRect category method?

If so I had the same problem, in IOS 5 the drawRect method is not called, IOS5 now has functions built in to customise the navigation bar.

IOS5 has a new appearance property which can be used to customise it, so what I did is check to see if the appearance property exists, if it does then you need to use the new appearance methods.

So I still have my drawRect category which is used when running on an IOS version < 5 and then in my view controller I do a check to see if the appearance object exists, if it does I then customise the navigation bar using that, now it works for both IOS 5 and below:

My viewDidLoad methods looks like below which sets the background of the navigation bar:

if ([self.navigationController.navigationBar respondsToSelector:@selector(appearance)]){
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"HeaderBar.png"] forBarMetrics:UIBarMetricsDefault];
}

You can also set the Appearance object for all navigation bars in your appDelegate by using the following code:

if ([UINavigationBar respondsToSelector:@selector(appearance)]){
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"HeaderBar.png"] forBarMetrics:UIBarMetricsDefault];
}

The code above is setting up the appearance on the UINavigationBar class rather than a single instance of the navigation bar. This means that IOS will apply the appearance to all navigationBars.

Craig Mellon
  • 5,399
  • 2
  • 20
  • 25