gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 13:14:27 25 4
gpt4 key购买 nike

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

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

我发现我们可以调整字偶距,但无法让这段代码正常工作

attributes: [NSKernAttributeName: 5.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

关于swift - 如何调整导航栏文本中的字距调整?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38386038/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com