How to change the font and text color of the title of UINavigationBar(如何更改 UINavigationBar 标题的字体和文字颜色)
问题描述
我想把标题的字体改成 Avenir,我想把它变成白色.这是我在 viewDidLoad
方法中的代码:
I want to be change the font of the title to Avenir, and I want to make it white. Here is my code in the viewDidLoad
method:
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: UIFont(name: "Avenir", size: 20)!]
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
此代码仅更改标题的颜色,而不更改字体.此外,我尝试在 App Delegate File 中实现这一点,但没有奏效.
This code only changes the color of the title, not the font. Additionally, I tried implementing this in the App Delegate File, but that did not work.
这是我的 UINavigationBar 的样子:
Here is what my UINavigationBar looks like:
我希望标题也有 Avenir 字体.我如何做到这一点?
I want the title to have a font of Avenir as well. How do I achieve this?
推荐答案
看来这个也是需要的:
self.navigationController?.navigationBar.barStyle = UIBarStyle.Black // I then set the color using:
self.navigationController?.navigationBar.barTintColor = UIColor(red: 204/255, green: 47/255, blue: 40/255, alpha: 1.0) // a lovely red
self.navigationController?.navigationBar.tintColor = UIColor.whiteColor() // for titles, buttons, etc.
let navigationTitleFont = UIFont(name: "Avenir", size: 20)!
self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: navigationTitleFont]
这篇关于如何更改 UINavigationBar 标题的字体和文字颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何更改 UINavigationBar 标题的字体和文字颜色


- GPS状态的广播接收器? 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- UITextView 内容插图 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- URL编码Swift iOS 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01