状态栏渐变

来源:互联网 发布:论文查重软件 编辑:程序博客网 时间:2024/06/04 18:01

         //首先声明,确定要渐变的颜色

          CAGradientLayer *_headerLayer;

          UIColor *colorOne = [UIColor colorWithRed:(0.0/255.0)  green:(0.0/255.0)  blue:(0.0/255.0)  alpha:0.7];

            UIColor *colorTwo = [UIColor colorWithRed:(0.0/255.0)  green:(0.0/255.0)  blue:(0.0/255.0)  alpha:0.0];

            

            NSArray *colors = [NSArray arrayWithObjects:(id)colorOne.CGColor, colorTwo.CGColor, nil];

            NSNumber *stopOne = [NSNumber numberWithFloat:0.0];

            NSNumber *stopTwo = [NSNumber numberWithFloat:1.0];

            NSArray *locations = [NSArray arrayWithObjects:stopOne, stopTwo, nil];

            

          

            if (!_headerLayer) {

                //crate gradient layer

                _headerLayer = [CAGradientLayer layer];

                

                _headerLayer.colors = colors;

                _headerLayer.locations = locations;

            }

            _headerLayer.frame = CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 20.0);

            [self.viewController.view.layer addSublayer:_headerLayer];


UIColor *colorOne = [UIColor colorWithRed:(0.0/255.0)  green:(0.0/255.0)  blue:(0.0/255.0)  alpha:0.7];

            UIColor *colorTwo = [UIColor colorWithRed:(0.0/255.0)  green:(0.0/255.0)  blue:(0.0/255.0)  alpha:0.0];

            

            NSArray *colors = [NSArray arrayWithObjects:(id)colorOne.CGColor, colorTwo.CGColor, nil];

            NSNumber *stopOne = [NSNumber numberWithFloat:0.0];

            NSNumber *stopTwo = [NSNumber numberWithFloat:1.0];

            NSArray *locations = [NSArray arrayWithObjects:stopOne, stopTwo, nil];

            

          

            if (!_headerLayer) {

                //crate gradient layer

                _headerLayer = [CAGradientLayer layer];

                

                _headerLayer.colors = colors;

                _headerLayer.locations = locations;

            }

            _headerLayer.frame = CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 20.0);

            [self.viewController.view.layer addSublayer:_headerLayer];


           UIColor *colorOne = [UIColor colorWithRed:(0.0/255.0)  green:(0.0/255.0)  blue:(0.0/255.0)  alpha:0.7];

            UIColor *colorTwo = [UIColor colorWithRed:(0.0/255.0)  green:(0.0/255.0)  blue:(0.0/255.0)  alpha:0.0];

            

            NSArray *colors = [NSArray arrayWithObjects:(id)colorOne.CGColor, colorTwo.CGColor, nil];

            NSNumber *stopOne = [NSNumber numberWithFloat:0.0];

            NSNumber *stopTwo = [NSNumber numberWithFloat:1.0];

            NSArray *locations = [NSArray arrayWithObjects:stopOne, stopTwo, nil];

            

          

            if (!_headerLayer) {

                //crate gradient layer

                _headerLayer = [CAGradientLayer layer];

                

                _headerLayer.colors = colors;

                _headerLayer.locations = locations;

            }

            _headerLayer.frame = CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 20.0);

            [self.viewController.view.layer addSublayer:_headerLayer];

原创粉丝点击