solid item color change bar swift uinavigationbar navigationbar

color - navigation item swift



¿Cómo cambio la fuente de navigationBar en Swift? (7)

¿Cómo cambio la fuente NavigationBar en Swift?

Esto es lo que he intentado hasta ahora, pero he recibido un error (he implementado CaviarDreams correctamente en el proyecto):

self.navigationController.navigationBar.titleTextAttributes = NSFontAttributeName[UIFont .fontWithName(CaviarDreams.ttf, size: 20)]

El error dice: Use of unresolved identifier ''CaviarDreams

Lo siento si la pregunta es extremadamente mala.


Ahora tiene que desenvolver (!) Primero, ¿no es de tipo UIFont? :

self.navigationController.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "<font-name>", size: <size>)!]


Para Swift 2.3

self.navigationController!.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "Roboto-Bold", size: 20.0)!, NSForegroundColorAttributeName : UIColor.whiteColor()];


Prueba esto:

self.navigationController.navigationBar.titleTextAttributes = [ NSFontAttributeName: UIFont(name: "CaviarDreams", size: 20)!]

Editar: Ahora, UIFont debe ser desenvuelto para poder ser utilizado aquí.


Swift 2.0:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { UINavigationBar.appearance().titleTextAttributes = [ NSFontAttributeName: UIFont(name: "Arial-Regular", size: 30)! ] return true }

O

override func viewDidLoad() { super.viewDidLoad() self.navigationController?.navigationBarHidden = false self.title = "SAMPLE" //Set Color let attributes: AnyObject = [ NSForegroundColorAttributeName: UIColor.redColor()] self.navigationController!.navigationBar.titleTextAttributes = attributes as? [String : AnyObject] //Set Font Size self.navigationController!.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "Arial", size: 37.0)!]; }


Usando Swift, agregué esto a AppDelegate.swift en

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. UINavigationBar.appearance().titleTextAttributes = [ NSFontAttributeName: UIFont(name: "DINNextLTW04-Regular", size: 20)! ] return true }

¡Espero eso ayude!


Swift 4.2

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. let font = UIFont(name: "FontName", size: 16) ?? UIFont.systemFont(ofSize: 16) UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.font: font] }


Swift 4

if let font = UIFont(name: "FontName", size: 16) { self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.font: font] }

O como la otra respuesta recomendada hacerlo en AppDelegate:

if let font = UIFont(name: "FontName", size: 16) { UINavigationBar.appearance().titleTextAttributes = [ NSAttributedStringKey.font: font] }