更改导航栏的字体

Joe*_*jah 64 iphone objective-c uinavigationbar uinavigationcontroller

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

你怎么能改变文字的字体UINavigationBar

Ara*_*han 158

从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
                                                      }];
Run Code Online (Sandbox Code Playgroud)

从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]
     }];
Run Code Online (Sandbox Code Playgroud)

早于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];
Run Code Online (Sandbox Code Playgroud)


ind*_*der 15

如果你想在Interface Builder中更改字体(没有任何代码),这就是在Xcode6中实现它的方法:

1.)在导航控制器场景下找到导航栏视图 在此输入图像描述

2.)在"属性"检查器中更改"标题字体","颜色"和"阴影"属性. 在此输入图像描述


小智 5

以上答案有效.我会在最后一行之前添加以下行.如果我不这样做,如果左侧有一个后退按钮但没有右按钮,则标签似乎不正确地居中对齐.

...
[self.navigationItem.titleView sizeToFit]; 
[label release]; // not needed if you are using ARC
Run Code Online (Sandbox Code Playgroud)


Abu*_*air 5

针对iOS 7进行了更新:

[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
                                                      [UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,
                                                      shadow, NSShadowAttributeName,
                                                      [UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil]];
Run Code Online (Sandbox Code Playgroud)

礼貌:

http://www.appcoda.com/customize-navigation-status-bar-ios-7/