美文网首页
状态栏背景颜色渐变

状态栏背景颜色渐变

作者: zhengelababy | 来源:发表于2017-07-20 16:07 被阅读19次

    //先声明

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

    相关文章

      网友评论

          本文标题:状态栏背景颜色渐变

          本文链接:https://www.haomeiwen.com/subject/bpqjkxtx.html