gpt4 book ai didi

ios - 如何设置导航栏字体和颜色

转载 作者:行者123 更新时间:2023-11-29 02:23:56 35 4
gpt4 key购买 nike

我正在尝试设置导航栏的颜色。我已将字体添加到 plist 文件中并将其添加为资源,并且在使用 UILabel 时可以在 Storyboard中选择它作为字体。所以字体似乎就在那里。

我已经在应用程序委托(delegate)中尝试过此操作:

NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:myLightBrownColor, NSForegroundColorAttributeName,[UIFont fontWithName:@"Pacifico" size:17.0f], NSFontAttributeName,
myShadow, NSShadowAttributeName, nil];
[navigationBarAppearance setTitleTextAttributes:textTitleOptions];

直接在 View Controller 中:

NSShadow *myShadow = [MRStyleController getMyShadow];
NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:[MRStyleController getLightBrownColor], NSForegroundColorAttributeName,[UIFont fontWithName:@"Pacifico" size:17.0f], NSFontAttributeName,
myShadow, NSShadowAttributeName, nil];
self.navigationController.navigationBar.titleTextAttributes = textTitleOptions;

但是,这一切都没有改变应用程序导航栏标题的字体和颜色。

有什么建议吗?

编辑:正确的做法是:

UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
[navigationBarAppearance setBarTintColor:myBrownColor];

NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:myLightBrownColor, NSForegroundColorAttributeName,
myShadow, NSShadowAttributeName,
[UIFont fontWithName:@"AmericanTypewriter" size:16.0], NSFontAttributeName, nil];
[navigationBarAppearance setTitleTextAttributes:textTitleOptions];

这会将字体更改为“American TypeWriter”。

但我有一个名为“Pacifico”的自定义字体,它在我的“支持文件”文件夹中,名为“Pacifico.ttf”,并在我的 info.plist 中列为“应用程序提供的字体”,但字体不是没有改变,所以不知何故自定义字体没有被正确引用?

最佳答案

导航栏标题使用

self.navigationController.navigationBar.titleTextAttributes= @{
NSForegroundColorAttributeName: [UIColor purpleColor],
NSFontAttributeName: [UIFont robotoMediumFontSize : 20.0],
};
self.navigationItem.title=@"MY Title";

用于设置导航栏背景色使用

self.navigationController.navigationBar.barTintColor=[UIColor myColor];

关于ios - 如何设置导航栏字体和颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27783935/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com