2012-02-05 134 views
2

我明白,你可以通过调用的setTitle方法navigationItem像这样改变的导航项目的标题:导航栏如何标题字体颜色字体样式

[[ViewController navigationItem] setTitle:@"Hello World"]; 

但是,我希望做更多的则只需更改导航项目的文本,我想更改颜色和字体样式。

是否有任何功能允许您更改导航栏标题的颜色?

回答

12

您可以简单地在viewdidload方法中添加和修改以下代码。或者,你甚至可以把导航栏上的图像

if ([[UINavigationBar class]respondsToSelector:@selector(appearance)]) { 
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"image.png"] forBarMetrics:UIBarMetricsDefault]; 
} 

[[UINavigationBar appearance] setTitleTextAttributes:@{ 
    UITextAttributeTextColor : [UIColor whiteColor], 
    UITextAttributeTextShadowColor : [UIColor blackColor], 
    UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetMake(1, 0)], 
    UITextAttributeFont : [UIFont fontWithName:@"System" size:25.0] 
}]; 

希望这有助于

+1

setTitleTextAttributes仅适用于iOS 5吗? – 2012-02-05 07:05:17

+0

感谢您的反馈!我只是检查了API,它看起来像titleTextAttributes函数是我正在寻找。但是,它仅适用于IOS5。我仍然在使用iPhone SDK 4.3,我似乎在IOS5中只能找到很多可用的功能。我可以注册开发人员计划以使用这些功能。 – RyzBeyond 2012-02-05 07:16:06

+0

你可能想看看这个教程,http://www.raywenderlich.com/4344/user-interface-customization-in-ios-5 – Clarence 2012-02-05 07:30:02

0

每一个的UINavigationController的导航栏是由导航项目。您可以使用UINavigationItem属性titleView,并返回包含所需字体大小,颜色,样式等的自定义视图。