【问题标题】:swift: Font of title in navigation barswift:导航栏中的标题字体
【发布时间】:2016-04-03 13:55:50
【问题描述】:

在 AppDelegate.swift 我有以下代码:

let nav1 = UINavigationController()
    let mainView = ViewController(nibName: nil, bundle: nil) //ViewController = Name of your controller
    nav1.viewControllers = [mainView]
nav1.navigationBar.topItem?.title = "JT"
    nav1.navigationController?.navigationBar.titleTextAttributes = [ NSFontAttributeName: UIFont(name: "AvenirNext-UltraLight", size: 24)!,  NSForegroundColorAttributeName: UIColor.whiteColor()]

但最后一行不会改变导航栏标题的字体 我该怎么办?

【问题讨论】:

  • 尝试使用较小的字体。
  • 你确定字体没有改变吗?许多字体看起来很相似。

标签: ios swift fonts navbar


【解决方案1】:

您可以通过 Storyboard 更改导航栏标题属性或尝试以下操作:

nav1.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "AvenirNext-UltraLight", size: 24)!,  NSForegroundColorAttributeName: UIColor.whiteColor()]

【讨论】:

    【解决方案2】:

    你可以像这样创建自己的titleView:

     let label=UILabel(frame: nav1.navigationBar.frame)
        label.textAlignment=NSTextAlignment.Center
        label.font=UIFont(name: "FONT HERE", size: 27)
        label.text="TITLE HERE"
        label.textColor=UIColor.blackColor()
        for item in nav1.navigationBar.items!{
           item.titleView=label 
        }
    

    【讨论】:

      猜你喜欢
      • 2017-01-19
      • 1970-01-01
      • 1970-01-01
      • 2012-03-26
      • 1970-01-01
      • 1970-01-01
      • 2020-07-09
      • 2020-04-01
      • 2012-01-14
      相关资源
      最近更新 更多