2015-11-03 88 views

回答

1

试试这个代码,这个是写在OBJ - C的,但你可以从这里

[[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, 
                  [UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil]]; 

得到想法上定制更多的选择,你可以检查this nice tutorial

2

尝试像titleTextAttributes属性的属性.. 。

let attributesDictionary = [NSFontAttributeName: UIFont(name: "your font name", size: 24)!, NSForegroundColorAttributeName : UIColor.whiteColor()] 
    UINavigationBar.appearance().titleTextAttributes = attributesDictionary 
0
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor], NSFontAttributeName:[UIFont fontWithName:@"mplus-1c-regular" size:21]}]; 
0

如果你想改变字体Ø在斯威夫特

[[UINavigationBar appearance] setTitleTextAttributes: 
    @{NSFontAttributeName:[UIFont systemFontOfSize:22], // font size 
    NSForegroundColorAttributeName:[UIColor yellowColor], // foreground color 
    NSBackgroundColorAttributeName:[UIColor blackColor]}]; // background color 

这样的::F所有的导航栏,您可以在OC做到这一点

UINavigationBar.appearance().titleTextAttributes = 
    [NSFontAttributeName:UIFont.systemFontOfSize(22), // font size 
    NSBackgroundColorAttributeName:UIColor.yellowColor(), // background color 
    NSForegroundColorAttributeName:UIColor.blackColor()] // foreground color 

但如果你只是想改变一些特定视图控制器,你可以在OC做到这一点:

[self.navigationController.navigationBar setTitleTextAttributes: 
    @{NSFontAttributeName:[UIFont systemFontOfSize:22], 
     NSForegroundColorAttributeName:[UIColor yellowColor], 
     NSBackgroundColorAttributeName:[UIColor blackColor]}]; 

,这在斯威夫特:

self.navigationController?.navigationBar.titleTextAttributes = 
     [NSFontAttributeName:UIFont.systemFontOfSize(22), 
      NSForegroundColorAttributeName:UIColor.yellowColor(), 
      NSBackgroundColorAttributeName:UIColor.blackColor()] 

希望这些可以有所帮助。