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

  • Post author:
  • Post category:其他


//设置导航条标题颜色

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


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

self


.


navigationItem


.


titleView




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




//设置导航栏背景色


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


+ (UIColor *)colorWithHexString:(NSString *)hexString alpha:(CGFloat)alpha
{
    unsigned int red, green, blue;
    NSRange range;
    range.length =2;
    
    range.location =0;
    [[NSScanner scannerWithString:[hexString substringWithRange:range]]scanHexInt:&red];
    range.location =2;
    [[NSScanner scannerWithString:[hexString substringWithRange:range]]scanHexInt:&green];
    range.location =4;
    [[NSScanner scannerWithString:[hexString substringWithRange:range]]scanHexInt:&blue];
    
    return [UIColor colorWithRed:(float)(red/255.0f)green:(float)(green/255.0f)blue:(float)(blue/255.0f)alpha:alpha];
}





版权声明:本文为oneTagTag原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。