更改导航栏的字体
回答
距离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. 如何更改导航栏的字体?
- 3. 更改Swift导航栏中的字体
- 4. 如何更改UIImagePickerController导航栏字体?
- 5. 更改导航栏的UIImagePickerController
- 6. 更改不同传送带上的导航栏字体颜色
- 7. 不能更改导航栏中的字体颜色
- 8. 更改按钮字体的文本颜色,在导航栏内
- 9. UIActivityViewController更改导航栏文字颜色
- 10. 导航栏字体颜色
- 11. 导航栏标题更改
- 12. 更改导航栏按钮
- 13. 更改活动导航栏
- 14. 导航栏更改高度
- 15. 我想更改导航栏字体大小
- 16. 侧栏导航改为导航栏中的顶部导航栏
- 17. 改变一个元素的字体颜色导航栏引导
- 18. 引导导航栏:overiding字体颜色
- 19. 更改折叠的导航栏颜色
- 20. 更改导航栏UIImagePickerController的标题
- 21. 我如何更改MFMailComposeViewController的导航栏?
- 22. 更改jqGrid中的导航栏图标
- 23. 更改pushViewController上的导航栏:
- 24. 更改tabbarcontroller的导航栏backgroundcolor
- 25. 更改折叠导航栏的宽度
- 26. 更改导航栏的背景
- 27. 更改导航栏的颜色
- 28. 更改侧栏导航的高度
- 29. TimelineJS:更改导航栏的高度?
- 30. 更改引导栏中的导航栏断点3.3.7
只是因为这是我得到的第一个结果,当我去谷歌搜索主题,并有一个更新的答案: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