iOS中Navbar设置渐变色效果

这里写图片描述

- (void) viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

    //状态栏高亮
    self.navigationController.navigationBar.barStyle = UIStatusBarStyleLightContent;
    //导航渐变色
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.colors = @[(__bridge id)[UIColor colorWithRed:255 green:70 blue:93 alpha:1].CGColor,(__bridge id)[UIColor colorWithRed:251 green:108 blue:42 alpha:1].CGColor];
    gradientLayer.locations = @[@0.3, @1.0];
    gradientLayer.startPoint = CGPointMake(0, 0);
    gradientLayer.endPoint = CGPointMake(1.0, 0);
    gradientLayer.frame = CGRectMake(0, -20, ScreenWidth, 64);
    [self.navigationController.navigationBar.layer addSublayer:gradientLayer];
}
展开阅读全文

没有更多推荐了,返回首页