我将标题设置如下,但是我也想更改文本的颜色,但是没有textattributes
,我想知道如何实现?
self.tabBarController?.navigationItem.title = "Settings"
我也尝试了以下操作,但它甚至没有显示标签。
let navLabel = UILabel()
let navTitle = NSMutableAttributedString(string: "Settings", attributes:[
NSAttributedString.Key.foregroundColor: UIColor.blue,
NSAttributedString.Key.font: UIFont.systemFont(ofSize: 17.0, weight: UIFont.Weight.light)])
navLabel.attributedText = navTitle
self.tabBarController?.navigationItem.titleView = navTitle
答案 0 :(得分:2)
尝试此代码,希望对您有所帮助。
Build Settings \ Swift Language Version:4.1
常规\部署目标:10.3
let attrsNormal = [NSAttributedStringKey.foregroundColor : UIColor.black,
NSAttributedStringKey.font : UIFont(name: "Arial", size: 14)!]
UITabBarItem.appearance().setTitleTextAttributes(attrsNormal,
for: UIControlState.normal)
答案 1 :(得分:0)
标签的大小合适吗?致电fitThatSize