本文介绍了如何更改 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 标题的字体和文字颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
The End


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)