繁体   English   中英

如何更改导航项目的字体?

[英]How to change font of navigation items?

我的NavigationBar上有几个导航项(“后退”按钮,“保存”按钮)。 我试图寻找相关的答案,但发现要么过时,要么全无。

我在navigationItem.leftBarButtonItem上尝试了setTitleTextAttributes,但是没有用。

我设法更改了NavigationBar标题的字体,仅此而已。 使用self.navigationBar.titleTextAttribues,对导航项执行相同的方法,但不起作用。

编辑:找到一个解决方案,但我必须在每个视图控制器的viewWillAppear上添加此

let barBtn = UIBarButtonItem(title: "Test", style: UIBarButtonItemStyle.Bordered, target: self, action: "backButtonPressed")
barBtn.setTitleTextAttributes([NSFontAttributeName: UIFont(name: FONT_HERE, size: 12)!], forState: UIControlState.Normal)
self.navigationItem.setHidesBackButton(true, animated: false)
self.navigationItem.setLeftBarButtonItem(barBtn, animated: false)

然后在我称为popViewControllerAnimated的地方添加backButtonPressed函数。

你们觉得怎么样? 有没有更简单的解决方案?

我建议您使用外观协议: https : //developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIAppearance_Protocol/index.html

这是我如何自定义导航栏外观的示例。

//导航栏标题[[UINavigationBar外观] setTitleTextAttributes:@ {NSFontAttributeName:[UIFont fontWithName:@“ myfont” size:20.0f],NSForegroundColorAttributeName:[UIColor whiteColor]}];

// Navigation bar buttons and background
[UINavigationBar appearance].tintColor = [UIColor whiteColor];
[UINavigationBar appearance].barTintColor = [UIColor teal];
[UINavigationBar appearance].translucent = NO;

暂无
暂无

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

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