views:

26

answers:

1

I've seen this question asked around before, and found an answer for how to do this in a simple view. But... when I go to a subsequent view pushed onto the view stack, manually setting the titleView doesn't work out. The titleView view gets pushed off to the right while the back button and its text take over the left half of the UI.

Is there a standard way to do this? I've noticed the Gowalla app apparently does it quite well. I've tried a multitude of approaches including categories, subclasses, etc and haven't had any luck.

+1  A: 

Every UIViewController has it's own navigationItem, which (potentially) has a titleView. When you push and pop view controllers in a navigation control, the parts of the navigationItem are what you are seeing. If you wanted a custom title color, you could very easily do something like the following in each of your view controllers.

- (UINavigationItem *)navigationItem
{
    UINavigationItem *navigationItem = [super navigationItem];
    UILabel *customLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320.0f, 44.0f)];
    customLabel.text = @"My Title";
    customLabel.textColor = [UIColor purpleColor];
    navigationItem.titleView = customLabel;
    [customLabel release];
    return navigationItem;
}
Jerry Jones
thanks for the tip. I ended up solving it by creating a custom view with two labels (i had requirements for title/subtitle in the nav bar) and then setting the bounds and width of the view frame so that it sat in the middle of the nav bar no matter if there were left/right buttons or not.
sw
Cool, glad it worked out for you.
Jerry Jones