美文网首页
ios更改导航栏颜色 字体大小 状态栏颜色

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

作者: jackguo | 来源:发表于2019-06-20 09:42 被阅读0次

参考 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];

}

相关文章

网友评论

      本文标题:ios更改导航栏颜色 字体大小 状态栏颜色

      本文链接:https://www.haomeiwen.com/subject/oearqctx.html