views:

95

answers:

2

Hi,

I am wanting to apply a custom alpha value to the title of the UINavigationBar. The UINavigationBar is part of the UINavigationController and the UINavigationController is part of a UITabBarController.

Edit: Here is a picture of what I created using a UIToolbar and a UILabel. I want to do the same using the title in the UINavigationController: http://i.imgur.com/B8YX0.png

I think the only way to accomplish this would be to subclass the UINavigationBar and override a method that allows me to set the Alpha when it's drawn. Here are my questions:

1) Is this the correct way to do this?

2) What are the HIG ramifications of this?

3) I am new to subclassing in Objective-C, can you provide a guide or tutorial that will help me grasp the steps required in subclassing a UI Element and implementing a change?

4) When I get the subclass configured, I can view it in IB by changing the class of the UINavigationBar to my custom class, correct?

5) Are there any "gotchas" that can come up with sublassing that an expert like yourself can give me a head's up on?

Thanks for your help in advance!

A: 

When a navigation bar is being managed by a navigation controller, there are only a few properties you're allowed to change (see docs). One of them is translucent which adjusts the alpha, but only to an Apple-determined value.

Brian
I'm not wanting to modify the translucent property of the NavigationBar itself, rather the title label contained within. Can I modify, via translucent, the alpha of the title? I added a link to the post to a photo of what I'm trying to accomplish.
Jesse Bunch
+2  A: 

This is something you shouldn't do. Why would you want to change that color but not the overal opacity of the bar? it decreases readability. There are multiple problems:

  • there is no public api, so it's not trivial
  • tempering with the subviews is fragile, may break and may have side-effects
  • it's not foreseen to be done -- the alpha value of the view is used and animated when pushing/popping a controller

If you really want to do it, there's only one clean, public way: Give each navigation item to be pushed a custom title view. You can temper with that one as much as you one. So it's possible to set a view with a UILabel as subview and having it's alpha set to 0.5.

Max Seelemann