ios更改导航栏颜色 字体大小 状态栏颜色

参考 https://www.jianshu.com/p/889cff2b3a52

- (void)viewWillAppear:(BOOL)animated{

    [superviewWillAppear:animated];


 //status bar的字体为白色 ,导航栏的背景色是黑色。  设置为UIBarStyleDefault statusbar 为黑色

 self.navigationController.navigationBar.barStyle= UIBarStyleBlack;


 //如果 info.plist 将View controller-based status bar appearance 设为 NO  改变 statusbar 颜色需要使用下边

    [UIApplicationsharedApplication].statusBarStyle= UIStatusBarStyleLightContent;

 //更改返回按钮的颜色

 self.navigationController.navigationBar.tintColor= [UIColorwhiteColor];


 // 设置导航栏title颜色和字体大小

 NSMutableDictionary*attributes = [NSMutableDictionarydictionary];

    attributes[NSForegroundColorAttributeName] = [UIColorwhiteColor];

    attributes[NSFontAttributeName] = GKBlodFont(AUTO(18));

 self.navigationController.navigationBar.titleTextAttributes= attributes;


#mark 由于我们要实现的效果  是在不同的页面导航栏的颜色不同 标题的颜色不同 有时候会遇到这个 title 的字体颜色不改变 可以使用下边的方法解决

UILabel *titleLabel = [[UILabel

alloc]initWithFrame:CGRectMake(0,0,200,44)];

titleLabel.backgroundColor = [UIColor grayColor];

titleLabel.font = [UIFont boldSystemFontOfSize:20];

titleLabel.textColor = [UIColor greenColor];

titleLabel.textAlignment=NSTextAlignmentCenter;

titleLabel.text = @"啊啊啊啊啊啊啊啊";

self.navigationItem.titleView = titleLabel;



 //设置导航栏的背景颜色

 UIImage*image = [XDCommonToolimageWithColor:RGB(254, 111, 89)];

    [self.navigationController.navigationBarsetShadowImage:image];

    [self.navigationController.navigationBarsetBackgroundImage:image forBarMetrics:UIBarMetricsDefault];


}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容