简体   繁体   English

标题字体在导航栏中不会更改

[英]Title Font doesn't change in Navigation Bar

I have a controller that is embedded in a Navigation Controller and I want to change the font of the title in the navigation bar. 我有一个嵌入在导航控制器中的控制器,我想在导航栏中更改标题的字体。 I want to use the storyboard, so it changes across the app (instead of creating a file for NavigationController and doing it via code); 我想使用故事板,因此它会在应用程序中发生变化(而不是为NavigationController创建文件并通过代码执行); not per controller: 不是每个控制器: 故事板

I am able to change the font size and color but I am not able to change the font family when using a custom font. 我可以更改字体大小和颜色,但在使用自定义字体时无法更改字体系列。 All other Xcode fonts work in this case. 在这种情况下,所有其他Xcode字体都有效。 I use the custom font everywhere in the app but it only doesn't work in case of Navigation. 我在应用程序的任何地方都使用自定义字体,但只有在导航时才能使用。

What can be the reason for this problem? 这个问题可能是什么原因?

I have the exactly same problem in Xcode 6.4. 我在Xcode 6.4中遇到了完全相同的问题。 This might be a bug of Xcode. 这可能是Xcode的一个错误。

For now, what you can do is to set custom font programmatically. 目前,您可以做的是以编程方式设置自定义字体。 ( Make sure you have your font ttf file in your project and add a property in Project Setting -> Info -> Fonts provided by application ) 确保项目中有字体ttf文件,并在项目设置 - >信息 - >应用程序提供的字体中添加属性

Swift: 迅速:

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

Objective-C: Objective-C的:

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

I had the same problem, but it seemed to appear just in storyboard. 我有同样的问题,但似乎只是出现在故事​​板中。 If you compile your app, it will work fine 如果您编译您的应用程序,它将正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM