如何更改导航栏的字体?
答案 0 :(得分:2)
尝试使用titleTextAttributes
属性...
let attributesDictionary = [NSFontAttributeName: UIFont(name: "your font name", size: 24)!, NSForegroundColorAttributeName : UIColor.whiteColor()]
UINavigationBar.appearance().titleTextAttributes = attributesDictionary
答案 1 :(得分: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 :(得分:0)
Saved GameData.plist file is --> Optional("{\n XInitializerItem = DoNotEverChangeMe;\n highscore = 25;\n}")
答案 3 :(得分:0)
如果您想更改所有导航栏的字体,可以在OC中执行此操作:
[[UINavigationBar appearance] setTitleTextAttributes:
@{NSFontAttributeName:[UIFont systemFontOfSize:22], // font size
NSForegroundColorAttributeName:[UIColor yellowColor], // foreground color
NSBackgroundColorAttributeName:[UIColor blackColor]}]; // background color
这在Swift:
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]}];
这在Swift:
self.navigationController?.navigationBar.titleTextAttributes =
[NSFontAttributeName:UIFont.systemFontOfSize(22),
NSForegroundColorAttributeName:UIColor.yellowColor(),
NSBackgroundColorAttributeName:UIColor.blackColor()]
希望这些有用。