当前位置:   article > 正文

设置导航标题颜色以及导航条背景色_yigesedaohang

yigesedaohang



//设置导航条标题颜色

  1. [self.navigationController.navigationBar setTitleTextAttributes: @{NSFontAttributeName:[UIFont systemFontOfSize:20],
  2. NSForegroundColorAttributeName:[UIColor whiteColor]}];

 

//或者自定义标题,新建一个lable赋给self.navigationItem.titleView 

  1. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, 320, 44)];
  2. titleLabel.backgroundColor = [CommonTools colorWithHexString:@"1680fa" alpha:1.0];
  3. titleLabel.font = [UIFont boldSystemFontOfSize:20];
  4. titleLabel.textColor = [UIColor whiteColor];
  5. titleLabel.textAlignment = NSTextAlignmentCenter;
  6. titleLabel.text = @"视频聊天";
  7. self.navigationItem.titleView = titleLabel;


//设置导航栏背景色

self.navigationController.navigationBar.barTintColor = [CommonTools colorWithHexString:@"1680fa" alpha:1.0];
colorWithHexString:@"1680fa" alpha:1.0取到的颜色接近于导航条

 
  1. + (UIColor *)colorWithHexString:(NSString *)hexString alpha:(CGFloat)alpha
  2. {
  3. unsigned int red, green, blue;
  4. NSRange range;
  5. range.length =2;
  6. range.location =0;
  7. [[NSScanner scannerWithString:[hexString substringWithRange:range]]scanHexInt:&red];
  8. range.location =2;
  9. [[NSScanner scannerWithString:[hexString substringWithRange:range]]scanHexInt:&green];
  10. range.location =4;
  11. [[NSScanner scannerWithString:[hexString substringWithRange:range]]scanHexInt:&blue];
  12. return [UIColor colorWithRed:(float)(red/255.0f)green:(float)(green/255.0f)blue:(float)(blue/255.0f)alpha:alpha];
  13. }




声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/457115
推荐阅读
相关标签
  

闽ICP备14008679号