ios 如何设置navbar渐变背景色
AppDelegate.m[UINavigationBarappearance].barStyle=UIStatusBarStyleLightContent;UIColo...
AppDelegate.m
[UINavigationBar appearance].barStyle = UIStatusBarStyleLightContent;
UIColor *color1= CustomColor(0, 187, 240 ,1.0);
UIColor *color2 = CustomColor(2, 86, 146, 1.0);
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.colors = @[(__bridge id)color1.CGColor,(__bridge id)color2.CGColor];
gradientLayer.locations = @[@0.3, @1.0];
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(1.0, 0);
gradientLayer.frame = CGRectMake(0, -20, Window_Width, 64);
[[UINavigationBar appearance].layer addSublayer:gradientLayer];
单独设置没又问题,但是全局的话就变黑色了 展开
[UINavigationBar appearance].barStyle = UIStatusBarStyleLightContent;
UIColor *color1= CustomColor(0, 187, 240 ,1.0);
UIColor *color2 = CustomColor(2, 86, 146, 1.0);
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.colors = @[(__bridge id)color1.CGColor,(__bridge id)color2.CGColor];
gradientLayer.locations = @[@0.3, @1.0];
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(1.0, 0);
gradientLayer.frame = CGRectMake(0, -20, Window_Width, 64);
[[UINavigationBar appearance].layer addSublayer:gradientLayer];
单独设置没又问题,但是全局的话就变黑色了 展开
1个回答
展开全部
#import "NavigationViewController.h"
#define LBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
@interface NavigationViewController ()
@end
@implementation NavigationViewController
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationBar.translucent = YES;
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
UIColor *color1= LBColor(255, 70, 93);
UIColor *color2 = LBColor(251, 108, 42);
gradientLayer.colors = @[(__bridge id)color1.CGColor, (__bridge id)color2.CGColor];
gradientLayer.locations = @[@0.5, @1.0];
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(1.0, 0);
gradientLayer.frame = CGRectMake(0, -20, self.view.frame.size.width, 64);
[self.navigationBar.layer addSublayer:gradientLayer];
}
追问
添加渐变色后,navbar上的控件都看不到(还可以点),要怎么处理?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询