iPhone UINavigationBar更改所有控制器的字体样式

我知道,我可以单独更改此答案中概述的导航栏的字体 : 更改导航栏的字体

目前我正在使用更全面的方法:

//in my app delegate: [[UINavigationBar appearance] setBarStyle:UIBarStyleBlackTranslucent]; 

有没有办法通过外观对象全局更改导航栏的字体?

谢谢!

来自Ray Wenderlich:

http://www.raywenderlich.com/4344/user-interface-customization-in-ios-5

 // Customize the title text for *all* UINavigationBars [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0], UITextAttributeTextColor, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset, [UIFont fontWithName:@"Arial-Bold" size:0.0], UITextAttributeFont, nil]]; 

@ Javy的回答@ Philip007的build议是:

 [[UINavigationBar appearance] setTitleTextAttributes: @{ UITextAttributeTextColor: [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0], UITextAttributeTextShadowColor: [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8], UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)], UITextAttributeFont: [UIFont fontWithName:@"Helvetica-Light" size:0.0f] }]; 

啊…那好多了!

上面的答案是更新已弃用的密钥和使用NSShadow

 NSShadow *shadow = [[NSShadow alloc] init]; shadow.shadowColor = [UIColor blackColor]; shadow.shadowBlurRadius = 0.0; shadow.shadowOffset = CGSizeMake(0.0, 2.0); [[UINavigationBar appearance] setTitleTextAttributes: @{ NSForegroundColorAttributeName : [UIColor blackColor], NSFontAttributeName : [UIFont fontWithName:@"Helvetica-Light" size:0.0f], NSShadowAttributeName : shadow }]; 

还将字体大小设置为0,以便根据导航栏方向/高度自动resize。