更改导航栏的字体 [英] Change the navigation bar's font

查看:103
本文介绍了更改导航栏的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题简单明了,答案很遗憾。

The question is plain easy and simple, the answer unfortunately not.

如何更改 UINavigationBar 中文本的字体?

How can you change the font of the text in the UINavigationBar?

推荐答案

从iOS 7及更高版本开始:

NSShadow* shadow = [NSShadow new];
shadow.shadowOffset = CGSizeMake(0.0f, 1.0f);
shadow.shadowColor = [UIColor redColor];
[[UINavigationBar appearance] setTitleTextAttributes: @{
     NSForegroundColorAttributeName: [UIColor greenColor],
                NSFontAttributeName: [UIFont fontWithName:@"Helvetica" size:20.0f],
              NSShadowAttributeName: shadow
                                                      }];

来自iOS 5及更高版本:

 [[UINavigationBar appearance] setTitleTextAttributes: @{
                                UITextAttributeTextColor: [UIColor greenColor],
                          UITextAttributeTextShadowColor: [UIColor redColor],
                         UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],
                                     UITextAttributeFont: [UIFont fontWithName:@"Helvetica" size:20.0f]
     }];

早于iOS 5:

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 400, 44)];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:20.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = UITextAlignmentCenter;
label.textColor =[UIColor whiteColor];
label.text=self.title;  
self.navigationItem.titleView = label;      
[label release];

这篇关于更改导航栏的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆