我可以改变我的UINavigationController的字体? - >标题更改字体
更改字体
回答
标题视图可以是任何图。因此,只需创建一个UILabel或更改字体并将该新视图分配给导航项目的title属性的其他内容。
一个例子:
-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
CGRect frame = CGRectMake(0, 0, 400, 44);
UILabel *label = [[[UILabel alloc] initWithFrame:frame] autorelease];
label.backgroundColor = [UIColor clearColor];
label.font = [FontHelper fontFor:FontTargetForNavigationHeadings];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.text = self.navigationItem.title;
// emboss in the same way as the native title
[label setShadowColor:[UIColor darkGrayColor]];
[label setShadowOffset:CGSizeMake(0, -0.5)];
self.navigationItem.titleView = label;
}
作为iOS 5中的可以经由代理外观改变字体。
https://developer.apple.com/documentation/uikit/uiappearance
下面我们来设置所有UINavigationControllers标题字体。
NSMutableDictionary *titleBarAttributes = [NSMutableDictionary dictionaryWithDictionary: [[UINavigationBar appearance] titleTextAttributes]];
[titleBarAttributes setValue:[UIFont fontWithName:@"Didot" size:16] forKey:NSFontAttributeName];
[[UINavigationBar appearance] setTitleTextAttributes:titleBarAttributes];
要设置后退按钮的字体,这样做:
NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary: [[UIBarButtonItem appearance] titleTextAttributesForState:UIControlStateNormal]];
[attributes setValue:[UIFont fontWithName:@"Didot" size:12] forKey:NSFontAttributeName];
[[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];
iOS 7弃用了键值:UITextAttributeFont(读取,不用这个)现在使用键:NSFontAttributeName来代替。工程奇迹,使我的应用程序看起来好多了。谢谢! – 2013-10-03 16:30:04
在每个单独的视图控制器中,您还可以在当前导航栏的实例上设置标题文本属性以自定义其外观,如下面的代码片段所示:[self.navigationController.navigationBar setTitleTextAttributes:@ {NSFontAttributeName:[UIFont fontWithName:@“帕拉提诺-粗体”尺寸:28],NSForegroundColorAttributeName:的UIColor whiteColor]}]; – CodePlumber 2015-03-21 16:53:23
为iOS8上的+,你可以使用:
[self.navigationController.navigationBar setTitleTextAttributes:@{ NSFontAttributeName: [UIFont fontWithName:@"MyFont" size:18.0f],
NSForegroundColorAttributeName: [UIColor whiteColor]
}];
从@morgancodes答案将设置所有的字体UINavigationController
标题。我已经更新了它的雨燕4:
let attributes = [NSAttributedStringKey.font: UIFont(name: "Menlo", size: 14) as Any]
UINavigationBar.appearance().titleTextAttributes = attributes
UIBarButtonItem.appearance().setTitleTextAttributes(attributes, for: .normal)
- 1. 更改字体
- 2. MessageBox.Show--字体更改?
- 3. 更改ListView字体
- 4. UINavigationBar更改字体
- 5. 字体和字体大小更改
- 6. 更改AS3组件字体
- 7. localStorage更改字体颜色
- 8. 加快字体更改
- 9. BlackBerry RichTextField更改字体
- 10. 更改字体大小macvim?
- 11. CFDocumentItem - 更改字体大小
- 12. DevExpress和C#字体更改
- 13. 更改字体样式
- 14. 更改JLabel的字体
- 15. NSAttributedString更改字体大小
- 16. Android键盘字体更改
- 17. Grid Pageable更改字体
- 18. 更改UINavigationBar字体属性?
- 19. CSS更改字体错误
- 20. 更改字体编程
- 21. 更改字体大小
- 22. WordPress的更改字体
- 23. 更改SWT Shell的字体
- 24. 更改吐司字体
- 25. 如何更改此字体?
- 26. getOrgChart字体大小更改
- 27. 更改字体颜色javascript
- 28. Eclipse Indigo字体已更改
- 29. 更改UITapGestureRecognizer中的字体
- 30. 离子更改字体
这是一个伟大的想法,但我现在有一个问题,.. 当我加我的UILabel我对UINavigationController的控件(如Add按钮)不再可见,.. * HM * – 2010-10-30 18:11:14
我固定它,用自己..对不起一个missunderstood;) – 2010-10-30 18:18:15
如果这解决了问题,不要忘记接受的答案 – Erik 2010-10-31 17:15:19