gpt4 book ai didi

ios - 在 Xcode 6.1 中设置导航栏文本字体

转载 作者:行者123 更新时间:2023-11-28 05:33:13 24 4
gpt4 key购买 nike

我在我的应用程序导航栏中使用了非默认字体,这在 Xcode 6.1 之前工作得非常好。现在我在定义字体类型和颜色的代码行中遇到错误。

这是我的代码:

    var attributes = [NSForegroundColorAttributeName: UIColor.whiteColor(),NSFontAttributeName: UIFont(name: "Avenir", size: 24)]
self.navigationController?.navigationBar.titleTextAttributes = attributes

我需要更改什么才能使其再次运行?

最佳答案

UIFont(name:size:) 返回一个可选的,它不能用作值。将其更改为:

var attributes = [NSForegroundColorAttributeName: UIColor.whiteColor(),NSFontAttributeName: UIFont(name: "Avenir", size: 24)!]

通过这样做,您将 UIFont? 值解包为 NSFontAttributeName。我相信您必须确保字体确实存在以避免崩溃。

关于ios - 在 Xcode 6.1 中设置导航栏文本字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26705671/

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