![](/img/trans.png)
[英]Change NavigationBar Title (font and color) in different View Controllers
[英]NavigationBar How to Title Font color font style
我知道您可以通过调用SetTitle方法navigationItem来更改导航项的标题,如下所示:
[[ViewController navigationItem] setTitle:@"Hello World"];
但是,我想做更多然后只需更改导航项的文本,我想改变颜色和字体样式。
是否有任何功能可以让您更改导航栏标题的颜色?
您只需在viewdidload方法中添加和修改以下代码即可。 或者您甚至可以在导航栏上放置图像
if ([[UINavigationBar class]respondsToSelector:@selector(appearance)]) {
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"image.png"] forBarMetrics:UIBarMetricsDefault];
}
[[UINavigationBar appearance] setTitleTextAttributes:@{
UITextAttributeTextColor : [UIColor whiteColor],
UITextAttributeTextShadowColor : [UIColor blackColor],
UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetMake(1, 0)],
UITextAttributeFont : [UIFont fontWithName:@"System" size:25.0]
}];
希望这有帮助
每个UINavigationController的导航栏都由导航项组成。 您可以使用UINavigationItem属性titleView,并返回一个自定义视图,其中包含您想要的任何字体大小,颜色,样式等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.