首页 文章

Headers 字体在导航栏中不会更改

提问于
浏览
5

我有一个嵌入在导航控制器中的控制器,我想在导航栏中更改 Headers 的字体 . 我想使用故事板,因此它会在应用程序中发生变化(而不是为NavigationController创建文件并通过代码执行);不是每个控制器:
Storyboard

我可以更改字体大小和颜色,但在使用 custom 字体时无法更改字体系列 . 在这种情况下,所有其他Xcode字体都有效 . 我在应用程序的任何地方都使用自定义字体,但只有在导航时才能使用 .

这个问题可能是什么原因?

2 回答

  • 11

    我在Xcode 6.4中遇到了完全相同的问题 . 这可能是Xcode的一个错误 .

    目前,您可以做的是以编程方式设置自定义字体 . ( Make sure you have your font ttf file in your project and add a property in Project Setting -> Info -> Fonts provided by application

    Swift:

    self.navigationController?.navigationBar.titleTextAttributes = [ NSFontAttributeName: UIFont(name: "LeagueGothic-Regular", size: 16.0)!, 
                                                                     NSForegroundColorAttributeName: UIColor.whiteColor()]
    

    Objective-C:

    [[UINavigationBar appearance] setTitleTextAttributes: 
        [NSDictionary dictionaryWithObjectsAndKeys: 
            [UIColor whiteColor], NSForegroundColorAttributeName, 
               [UIFont fontWithName:@"LeagueGothic-Regular" size:16.0], NSFontAttributeName,nil]];
    
  • 0

    我有同样的问题,但似乎只是出现在故事板中 . 如果您编译您的应用程序,它将正常工作

相关问题