2012-02-05 140 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,並返回包含所需字體大小,顏色,樣式等的自定義視圖。