iphone - 更改导航栏的字体

标签 iphone objective-c uinavigationcontroller uinavigationbar

这个问题简单明了,不幸的是答案不是。

如何更改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];

关于iphone - 更改导航栏的字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5832036/

相关文章:

ios - 当核心数据文件损坏时如何绕过警报消息?

iOS 日历事件 View 表示

ios - Swift 调用 setNavigationBarHidden 但 View 不会移动到顶部

iphone - 检测wifi是否开启 - iOS

ios - didSelectRowAtIndexPath 与 Tap Gesture Recognizer 冲突

iphone - 导航栏隐藏状态栏

javascript - 无需渲染命令的 React-Native 导航

iphone - 访问可以更新的固定应用程序资源的正确方法是什么?

iphone - 通用应用程序工作流程

ios - Branch.io 仅在应用程序已存在于设备中时才重定向到应用程序商店