swift - 如何在导航栏文本中调整字距?

时间:2016-07-15 00:10:07

标签: swift uinavigationcontroller spacing kerning

我在导航栏的文本字距调整中没有看到任何内容。有人知道怎么做吗?我在ViewDidLoad()

中设置了文本
df
#    KEGGnumber        Cor
# X1          2 -0.2623973
# X2       5, 7 -0.2241113
# X3          4 -0.3066684
# X4       3, 4 -0.2369324

df2
#        Col1   Col2
# 1    Formic C00058
# 2 Methanoic C00058
# 3  Ethanoic C00033
# 4    Acetic C00033
# 5 Propionic C00163
# 6 Propanoic C00163
# 7   Butyric C00246

我发现我们可以调整字距调整但无法使此代码正常工作

 self.navigationController?.navigationBar.topItem?.title = "My Nav Title"
self.navigationController?.navigationBar.titleTextAttributes = [ NSFontAttributeName: UIFont(name: "Helvetica", size: 20)!, NSForegroundColorAttributeName: UIColor.whiteColor()]

非常感谢!!!

1 个答案:

答案 0 :(得分:0)

我在之前的帖子中发现并修改了这段代码,现在可以在xcode 7.3.1

中使用了
    let titleLabel = UILabel()

    let attributes: NSDictionary = [
        NSFontAttributeName:UIFont(name: "Helvetica", size: 20)!,
        NSForegroundColorAttributeName:UIColor.blackColor(),
        NSKernAttributeName:CGFloat(8.0)
    ]

    let attributedTitle = NSAttributedString(string: ""My Nav Title", attributes: attributes as? [String : AnyObject])

    titleLabel.attributedText = attributedTitle
    titleLabel.sizeToFit()
    self.navigationItem.titleView = titleLabel