How do i change navigationBar font in Swift?

前端 未结 9 1191
伪装坚强ぢ
伪装坚强ぢ 2020-12-23 20:16

How do I change the NavigationBar font in Swift?

This is what I have tried so far, but receiving an error (I have correctly implemented CaviarDreams

相关标签:
9条回答
  • 2020-12-23 21:14

    Now you have to unwrap (!) it first so its not of type UIFont?:

    self.navigationController.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "<font-name>", size: <size>)!]
    
    0 讨论(0)
  • 2020-12-23 21:19

    Using Swift, I added this to AppDelegate.swift in

    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
        }
    

    Hope it helps!

    0 讨论(0)
  • 2020-12-23 21:19

    Swift 2.0:

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

    Or

     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)!];
    
     }
    
    0 讨论(0)
提交回复
热议问题