我想要更改导航栏的字体。然而,下面的代码无法生效,它会导致应用程序崩溃。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: UIFont(name: "Lato-Light.ttf", size: 34)!]
return true
}
我遇到了以下错误:
致命错误:在解包可选值时意外地发现了 nil(lldb)
我确实将字体Lato-Light.ttf添加到了我的项目中,所以应该能够找到它。
UIFont { class var navbarTitleFont: UIFont { return UIFont(name: "HelveticaNeue", size: 20) ?? UIFont.systemFontOfSize(20) }
- Nat