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 标题的字体和文字颜色


基础教程推荐
- 在 iOS 7 下 CCMenu 错位 2022-01-01
- Android - 如何在runOnUiThread 中将数据传递给Runnable? 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Firebase 云消息传递令牌未生成 2022-01-01
- 更改 UITableView 部分标题的颜色 2022-01-01
- 在视图控制器的宽度上水平均匀分布 UIButton 的最简单方法? 2022-01-01
- UINavigationItem 的持久 rightBarButtonItem 属性 2022-01-01
- UINavigationBar 隐藏按钮文本 2022-01-01
- 从 UIWebView 访问元数据 2022-01-01
- EditText 中的 setHintTextColor() 2022-01-01