开发者

Changing text color in UINavigationBar

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 m开发者_Go百科ultitude of approaches including categories, subclasses, etc and haven't had any luck.


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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜