1. 程式人生 > >iOS中Navbar設定漸變色效果

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]; }