iOS更改导航栏标题的字体和颜色 [英] iOS change navigation bar title font and color
本文介绍了iOS更改导航栏标题的字体和颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
NSDictionary * attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont
fontWithName:_dataManager.optionsSettings.fontString size:14],NSFontAttributeName,
[UIColor whiteColor],NSForegroundColorAttributeName,nil];
[[UINavigationBar appearance] setTitleTextAttributes:attributes];
使用此代码更改后退按钮的字体效果很好。
// set backbutton font
NSDictionary * normalAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:_dataManager.optionsSettings.fontString size:15], NSFontAttributeName,
nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:normalAttributes
forState:UIControlStateNormal];
解决方案
改变标题字体)是:
$ b $ pre $ [self.navigationController.navigationBar setTitleTextAttributes:
@ {NSForegroundColorAttributeName:[UIColor redColor],
NSFontAttributeName:[UIFont fontWithName:@mplus-1c-regularsize:21]}];
Swift:
self.navigationController?.navigationBar.titleTextAttributes =
[NSForegroundColorAttributeName:UIColor.redColor(),
NSFontAttributeName:UIFont(name:mplus-1c-regular,size:21)! ]
So i have this code that should change the nav bar title font, but it doenst
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont
fontWithName:_dataManager.optionsSettings.fontString size:14], NSFontAttributeName,
[UIColor whiteColor], NSForegroundColorAttributeName, nil];
[[UINavigationBar appearance] setTitleTextAttributes:attributes];
Changing the back button font with this code works just fine.
//set backbutton font
NSDictionary *normalAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:_dataManager.optionsSettings.fontString size:15], NSFontAttributeName,
nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:normalAttributes
forState:UIControlStateNormal];
解决方案
The correct way to change the title font (and color) is:
[self.navigationController.navigationBar setTitleTextAttributes:
@{NSForegroundColorAttributeName:[UIColor redColor],
NSFontAttributeName:[UIFont fontWithName:@"mplus-1c-regular" size:21]}];
Swift:
self.navigationController?.navigationBar.titleTextAttributes =
[NSForegroundColorAttributeName: UIColor.redColor(),
NSFontAttributeName: UIFont(name: "mplus-1c-regular", size: 21)!]
这篇关于iOS更改导航栏标题的字体和颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文