0

I am using iOS 5 UINavigationBar's UIAppearance protocol in order to customise all my navigation bars.

Here is my customisation function:

- (void)customizeApperance
{
    [[UINavigationBar appearance] setTintColor:[UIColor clearColor]];
    [[UINavigationBar appearance] setAlpha:0.7];
    UIImageView *titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title.png"]];
    [[UINavigationBar appearance] setTitleView:titleView];
}

I have two problems:

  • The first is that the colour not appearing as clearColor but black. Any suggestions?

  • The title view is not appearing at all. Ray Wenderlich shows how to do that by adding a: [[rootViewController navigationItem] setTitleView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"miniLogo.png"]]] in applicationDidFinishLaunching. But the problem with this is that the title view would only be added in the root view controller. I am using a UINavigationController and when I tired to replace the rootViewController with navigationController (the name of my navigation controller in AppDelegate), I cannot see the title view at all. How can I fix that? Why isn't it working in customizeApperance()? Isn't the whole point of using appearance is to just create a title view once (as I did above the function) and have it global in all navigation bars? How can I achieve that?

darksky
  • 20,411
  • 61
  • 165
  • 254
  • This post might help you. [custom-uinavigationbar-background][1] [1]: http://stackoverflow.com/questions/704558/custom-uinavigationbar-background – prashant Sep 13 '12 at 17:03

3 Answers3

6

[UIColor clearColor] is a fully transparent color (alpha = 0). Setting that as tint color makes the (black) background shine through. Perhaps you want [UIColor whiteColor] ?

titleView is a property of UINavigationItem, and each view controller has it's own navigationItem. Therefore you cannot set a title view globally. But you can set the background image of UINavigationBar with the appearance protocol, perhaps that helps:

[[UINavigationBar appearance] setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];  
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • I actually wanted `clearColor` so that the background behind it is shown transparently. Can that be done? – darksky Sep 13 '12 at 18:09
  • @Darksky: Try `self.navigationController.navigationBar.translucent = YES;` . – Martin R Sep 14 '12 at 13:23
  • @MartinR that works for making the bar translucent, however, the buttons are still solid black. See the image in http://stackoverflow.com/questions/3081203/custom-background-transparent-background-on-uibarbuttonitem – Kudit Oct 04 '12 at 16:25
  • @Gujamin: Thank you for the info. My problem was that I did not know what Darksky wanted to achieve exactly. And I do not know if he still needs an answer for this, there was no feedback for some time now. – Martin R Oct 04 '12 at 18:09
1

Have you tried titleView.opaque = NO;? If that's set to YES (i.e. by default, since you're using initWithImage:), the drawing system will assume your view fills its entire bounds, and won't bother drawing anything that overlaps its frame.

Ryan Artecona
  • 5,953
  • 3
  • 19
  • 18
0

setTitleView: is a method on NavigationItem. But you are calling it on navigation bar

Atif Khan
  • 125
  • 1
  • 7