Ich habe einen Titel in meiner Navigationsleiste und möchte ihn in eine benutzerdefinierte Schriftart ändern. Ich habe diese Codezeile gefunden, aber wenn Sie einen Navigationscontroller haben.
self.navigationController?.navigationBar.titleTextAttributes = [ NSFontAttributeName: UIFont(name: "LeagueGothic-Regular", size: 16.0)!,
NSForegroundColorAttributeName: UIColor.whiteColor()]
Ich habe jedoch keinen Navigationscontroller. Ich habe die Navigationsleiste manuell in meine Ansicht eingefügt.
Wie kann ich die Kommentarschriftart ändern?
Antworten:
27 für die Antwort № 1Versuche dies:
Ziel c
[[UINavigationBar appearance] setTitleTextAttributes:attrsDictionary];
Schnell 3
self.navigationController.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "CaviarDreams", size: 20)!]
Schnell 4
self.navigationController.navigationBar.titleTextAttributes = [NSAttributedStringKey.font: UIFont(name: "CaviarDreams", size: 20)!]
13 für die Antwort № 2
So legen Sie die Schrift für jeden Ansichts-Controller in Swift fest (unter Verwendung von Appearance Proxy)
Schnell 4
let attributes = [NSAttributedStringKey.font: UIFont(name: "HelveticaNeue-Light", size: 17)!]
UINavigationBar.appearance().titleTextAttributes = attributes
Schnell 3
let attributes = [NSFontAttributeName: UIFont(name: "HelveticaNeue-Light", size: 17)!]
UINavigationBar.appearance().titleTextAttributes = attributes
-1 für die Antwort № 3
Um titleTextAttributes im Verweis auf die Navigationsleiste aufzurufen, verwenden Sie:
let attributes = [NSAttributedStringKey.font: UIFont(name: "Helvetica", size: 17)!]
self.navigationController?.navigationBar.titleTextAttributes = attributes