0

I have a view controller that's embedded in a navigation controller. Therefore this view controller has a navigation item at the top. One of the things you can do in ios6 storyboards is that you can set the title, prompt and back button for this view controller (because its embedded in a navigation controller).

That being said, when I specify a title and test the app, everything looks good. However, when I place a transparent UIView on top of the navigation item (such as where the title is), the title itself just vanishes. The text itself that I typed into interface builder is gone. I have proven this because if I delete the view I created, the text I initially had is gone.

I tried to mediate the problem by actually setting the title itself outside of the interface builder:

self.navigationItem.title=@"My Title";

But that doens't seem to work either. Does anyone have a clue as to how I can hide/show a transparent UIView on top of a navigationItem in a navigation controller?

EDIT

Any UI element I place in the navigation controller toolbar seems to prevent the underlying title text from showing up. This happens even if the element is marked as transparent AND its set to hidden.

AbuZubair
  • 1,236
  • 14
  • 20

2 Answers2

1

My understanding is that Interface Builder is, more or less, mimicking what you would do if you did the same thing programmatically using the UIBarButtonItem class. The various items in a navigation bar are instances of the UIBarButtonItem class. This class has the following initializers:

– initWithBarButtonSystemItem:target:action:
– initWithCustomView:
– initWithImage:style:target:action:
– initWithTitle:style:target:action:
– initWithImage:landscapeImagePhone:style:target:action:

When you just have a title for the navigation controller, Interface Builder treats it similar to using the initWithTitle: initializer. Basically, this means that, under the hood, a UILabel class is created with the given title and that UILabel is used as the view for the UIBarButtonItem.

When you are dragging the transparent view over the title, however, Interface Builder is instead doing the equivalent of calling initWithCustomView:. This means that the view you are providing is being used as the UIBarButtonItem's view. In other words, when you drag the custom view over the title, you are not placing it on top of the title. You are replacing the title with the transparent view.

One option might be to create a view which has both a UILabel and the transparent view as subviews. Then place that view as the title for the navigation bar. If you give that UILabel the correct font size and shadow, it will look indistinguishable from the system's default title and you will also be able to have the transparent view on top of it.

Matthew Gillingham
  • 3,429
  • 1
  • 22
  • 26
  • Yes I was able to get the default font/size setup from this post: http://stackoverflow.com/questions/599405/iphone-navigation-bar-title-text-color/13694535#13694535 – AbuZubair Dec 04 '12 at 01:24
  • I had one more question though. I'll need a progressbar, the label for the progressbar and the navigation controller title all in one crammed little area. Does having three UI elements in one view really make sense? It just gets so crowded in interface builder. – AbuZubair Dec 04 '12 at 01:25
  • There is nothing fundamentally wrong with having three UI elements in a single view. You are right that you will be need to be careful about how to lay it out so that it still looks good to the user. – Matthew Gillingham Dec 04 '12 at 01:33
  • Well they will never be present in the same time. I am just doing some switches on hidden calls so that I simulate the effect that happens when you use messages. Meaning that you see the contact's name at the top normally, but when you send a message, it switches to a label that says 'uploading' followed by a progress bar. When the message is sent, it reverts to the contact's name. Therefore the real estate in this small area is mutually exclusive. The problem however is dealing with in interface builder because you see it all at once. Nonetheless I will deal with it. Thanks! – AbuZubair Dec 04 '12 at 01:34
0

In IB, you can drag a UIView to the center of the navigation bar, and this will replace the titleView that is there by default (you can do it in code with setTitleView:). If you make its background clear and add a label to it to hold the title, it will look like the default title. You can then add another UIView as the subview of this view, just like you would with any other UIView.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • So you are saying I would have to add a label with the same text size/font as the original title I had onto the view itself? There is no way I can have the underlying title expose itself through a transparent overlay-ed view? – AbuZubair Dec 04 '12 at 00:35
  • Yes, you have to add your own view -- it could just be the label itself, or any other subclass of UIView. Look at the reference for the titleView property, it explains that if you set one, it takes the place of the standard title. – rdelmar Dec 04 '12 at 01:38