ios - Change font in navigation bar in Swift -
I want to change the font in the navigation bar, though the following code is not working, this causes the application to crash .
func application (application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) - & gt; Bull {UINavigationBar.appearance (). TitleTextAttributes = [NSFontAttributeName: UIFont (name: "Lato-Light.ttf", Size: 34)!] Return true}
I get the following error:
Fatal error: Unexpectedly found zero during opening an optional value (LLDB)
I have actually added the font Lato-Light Has been sent to its project, so it should be able to find it.
UIFont ()
is a fusible intiLiizer, it fails for several reasons Could. ! A forced opening crashes your app using
.
Start it better separately and check success:
if font = UIFont (name: "Lato-Light.ttf", size: 34) {UINavigationBar.appearance (). TitleTextAttributes = [NSFontAttributeName: font]}
and check whether your font file is included in bundled resources.
Comments
Post a Comment