【发布时间】:2018-10-01 16:59:49
【问题描述】:
我想更改自定义导航栏的背景颜色以及标题字体颜色、字体样式和字体大小。所以我在 AppDelegate.swift 文件中尝试了这段代码
UINavigationBar.appearance().barTintColor = UIColor(red: 0/255, green: 162/255, blue: 255/255, alpha: 1.0)
UINavigationBar.appearance().tintColor = UIColor.white
let navigationTitleFont = UIFont(name: "Poppins", size: 20)!
let navigaiontitlecolor = UIColor.white
UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor : navigaiontitlecolor]
UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.font : navigationTitleFont]
我得到了背景颜色。我的标题字体样式和大小都可以。但我的标题字体颜色不对。所以我去搜索并应用了这个链接代码
Change Both Title Text Color and Font in all Navigation Bars
但在我的情况下不起作用。怎么办?
【问题讨论】:
-
您的代码看起来不错。检查它是否在其他地方改变了它。
-
您没有阅读@matt 对exact 相同问题的回答。
-
@matt 的回答无效。
-
您确定@matt 的回答有效吗?先生。
-
因为它向我显示这样的错误:Use of unresolved identifier 'NSfontAttributedName