如何更改 UINavigationBar 标题的字体和文字颜色 [英] How to change the font and text color of the title of UINavigationBar

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆