更改導航欄的字體
回答
距離Ios 7和更高:
NSShadow* shadow = [NSShadow new];
shadow.shadowOffset = CGSizeMake(0.0f, 1.0f);
shadow.shadowColor = [UIColor redColor];
[[UINavigationBar appearance] setTitleTextAttributes: @{
NSForegroundColorAttributeName: [UIColor greenColor],
NSFontAttributeName: [UIFont fontWithName:@"Helvetica" size:20.0f],
NSShadowAttributeName: shadow
}];
距離Ios 5和更高:
[[UINavigationBar appearance] setTitleTextAttributes: @{
UITextAttributeTextColor: [UIColor greenColor],
UITextAttributeTextShadowColor: [UIColor redColor],
UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],
UITextAttributeFont: [UIFont fontWithName:@"Helvetica" size:20.0f]
}];
比iOS 5的早些時候:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 400, 44)];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:20.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = UITextAlignmentCenter;
label.textColor =[UIColor whiteColor];
label.text=self.title;
self.navigationItem.titleView = label;
[label release];
當您向下鑽取並返回時,消失... – ozba 2012-11-05 11:13:28
請提醒這個答案已經過時。有很多簡單的方法可以在iOS 5和6中自定義UI元素的外觀。只需使用「外觀」代理即可。 – Philip007 2012-11-09 11:59:19
如何讓此代碼使用SystemFont而不是硬編碼到Helvetica? – Brabbeldas 2015-11-01 16:54:20
以上答案有效。我會在最後一行之前添加以下行。如果我不這樣做,看起來標籤如果在左側有後退按鈕但沒有右側按鈕,則中心對齊方式不正確。
...
[self.navigationItem.titleView sizeToFit];
[label release]; // not needed if you are using ARC
從iOS 5開始,您可以使用外觀代理。
答案是在這個問題上的副本:https://stackoverflow.com/a/12364740/883413
更新了iOS的7:
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,
shadow, NSShadowAttributeName,
[UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil]];
禮節:
http://www.appcoda.com/customize-navigation-status-bar-ios-7/
NSShadow *shadow = [NSShadow new];
[shadow setShadowColor: [UIColor clearColor]];
[shadow setShadowOffset: CGSizeMake(0.0f, 1.0f)];
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"TimeBurner" size:27.0f], NSFontAttributeName,
[UIColor whiteColor], NSForegroundColorAttributeName,
shadow, NSShadowAttributeName,nil]];
我已經下載了名爲timeburner_regular.ttf的字體,所以我寫了上面的代碼。它爲我工作。 – Vin 2014-03-06 14:06:33
如果你想改變Interface Builder本身的字體(沒有任何代碼)這裏是做在Xcode6方式:
1)查找下導航控制器場景
2.導航欄視圖)更改標題字體,顏色和陰影的屬性屬性督察。
不知道爲什麼所有的答案都包含了陰影。添加操縱陰影的線不會改變文字字體。這些2行的代碼會爲的iOS 8.4工作和夫特
let attributesDictionary = [NSFontAttributeName: UIFont(name: "Helvetica Neue", size: 14)!]
navigationController!.navigationBar.titleTextAttributes = attributesDictionary
的titleTextAttributes
存儲的字典,將決定的字體,顏色,大小,和導航欄的標題的其它屬性。
而文本的默認顏色將是'UINavigationBar'的'tintColor'。如果您想要不同的東西,請設置色調顏色,或者將「NSForegroundColorAttributeName」屬性和值添加到該屬性字典中。 – NRitH 2015-08-24 00:44:40
如何讓這個使用SystemFont? – Brabbeldas 2015-11-01 16:53:47
- 1. 更改導航欄字體
- 2. 更改Swift導航欄中的字體
- 3. 如何更改導航欄的字體?
- 4. 如何更改UIImagePickerController導航欄字體?
- 5. 改變字體/導航欄中
- 6. 更改導航欄的UIImagePickerController
- 7. 不能更改導航欄中的字體顏色
- 8. 更改不同傳送帶上的導航欄字體顏色
- 9. 更改按鈕字體的文本顏色,在導航欄內
- 10. iPhone導航欄字體
- 11. 導航欄字體顏色
- 12. 更改導航欄按鈕
- 13. 更改活動導航欄
- 14. 動態更改導航欄
- 15. 導航欄標題更改
- 16. 導航欄更改高度
- 17. 更改導航欄高度
- 18. 我想更改導航欄字體大小
- 19. 側欄導航改爲導航欄中的頂部導航欄
- 20. 引導導航欄:overiding字體顏色
- 21. 更改導航欄的顏色
- 22. 更改UIDocumentInteractionController導航欄的顏色
- 23. 如何更改導航欄的高度?
- 24. 更改UIActivityViewController的導航欄顏色
- 25. 更改導航欄UIImagePickerController的標題
- 26. 更改tabbarcontroller的導航欄backgroundcolor
- 27. 更改摺疊導航欄的寬度
- 28. 更改導航欄的背景
- 29. 更改摺疊的導航欄顏色
- 30. Swift - iOS:更改導航欄的顏色
只是因爲這是我得到的第一個結果,當我去谷歌搜索主題,並有一個更新的答案:http://stackoverflow.com/a/10440362/700471 – 2012-10-12 17:59:41
我相信有一個區別兩個問題。在我要求更改單個導航欄的字體的地方,另一個問題是關於更改「全部」導航欄的字體。儘管如此,這是一個有用的鏈接,可以提及其他人可能感興趣的內容! – Joetjah 2012-10-22 12:07:48
對於單個導航欄,請使用:[self.navigationController。navigationBar setTitleTextAttributes:@ {UITextAttributeFont:[UIFont fontWithName:<#(NSString *)#> size:<#(CGFloat)#>]}];' – Philip007 2012-11-09 11:56:14