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

查看:361
本文介绍了如何更改UINavigationBar标题的字体和文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想把标题的字体改成Avenir,我想把它变成白色。这是我在 viewDidLoad 方法中的代码:

  UINavigationBar.appearance ).titleTextAttributes = [NSFontAttributeName:UIFont(name:Avenir,size:20)!] 
UINavigationBar.appearance()。titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]

这段代码只改变标题的颜色,而不是字体。另外,我尝试在应用程序委托文件中实现这一点,但是这不起作用。

以下是我的UINavigationBar:



I希望标题也有Avenir的字体。

解决方案

我使用这个:

更新,这似乎也是需要的:

  self.navigationController?.navigationBar.barStyle = UIBarStyle.Black //然后我设置颜色使用:

self.navigationController?.navigationBar.barTintColor = UIColor(红色:204/255,绿色:47/255,蓝色:40/255,alpha:1.0)//一个可爱的红色

self.navigationController?.navigationBar.tintColor = UIColor.whiteColor()//用于标题,按钮等

让navigationTitleFont = UIFont(name:Avenir ,大小:20)!

self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName:navigationTitleFont]


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()]

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.

Here is what my UINavigationBar looks like:

I want the title to have a font of Avenir as well. How do I achieve this?

解决方案

I use this:

Update, it seems this is needed as well:

    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天全站免登陆