导航栏设置的颜色由于系统在导航栏上面添加了蒙版的效果,所以设置上颜色值和实际上有一定的偏差
为了解决颜色上的偏差 创建一个继承自UINavigationController的类
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationBar setBackgroundImage:[[UIImage alloc]init] forBarMetrics:UIBarMetricsDefault];
[self.navigationBar setShadowImage:[[UIImage alloc]init]];
[self.navigationBar.layer.sublayers.firstObject addSublayer:[self gradientLayer]];
}
- (CAGradientLayer *)gradientLayer
{
CAGradientLayer *gradientLayer = [[CAGradientLayer alloc]init];
gradientLayer.backgroundColor = [UIColor colorWithRed:28/255.0 green:166/255.0 blue:248/255.0 alpha:1].CGColor;
gradientLayer.frame = CGRectMake(0, 0, self.navigationBar.bounds.size.width, 20 + self.navigationBar.bounds.size.height);
return gradientLayer;
}
网友评论