navigationBar设置纯色颜色

 self.view.backgroundColor = [UIColor colorWithRed:58.0/255.0 green:190.0/255.0 blue:0 alpha:1.0];
//这里要设置背景色为透明,否则状态栏颜色会不统一
    [self.navigationBar setBackgroundColor:[UIColor clearColor]];
//tintColor为barItem按钮text的颜色
    self.navigationBar.tintColor = [UIColor whiteColor];
    [self.navigationBar setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithRed:58.0/255.0 green:190.0/255.0 blue:0 alpha:1.0]]
                             forBarMetrics:UIBarMetricsDefault];
    self.navigationBar.translucent = YES;
//根据颜色返回图片
+(UIImage*) imageWithColor:(UIColor*)color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

你可能感兴趣的:(navigationBar设置纯色颜色)