Reputation: 4607
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.
Upvotes: 0
Views: 3616
Reputation: 5403
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; }
Upvotes: 4