美文网首页
border渐变色(CAGradientLayer)

border渐变色(CAGradientLayer)

作者: huxinwen | 来源:发表于2019-12-13 15:33 被阅读0次
    - (void)addBorder {
        [self removeBorder];
        UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bgView.bounds cornerRadius:5*SCALE_2X];
        //遮罩层
        CAShapeLayer *progressLayer = [CAShapeLayer layer];
        progressLayer.frame = self.bgView.bounds;
        progressLayer.fillColor =  [[UIColor clearColor] CGColor];
        progressLayer.strokeColor=[UIColor redColor].CGColor;
        progressLayer.path=path.CGPath;
        //渐变图层
        _borderLayer =  [CAGradientLayer layer];
        _borderLayer.frame = progressLayer.frame;
        [_borderLayer setColors:[NSArray arrayWithObjects:(id)[[UIColor colorWithHexString:@"06fffe"] CGColor],(id)[[UIColor colorWithHexString:@"d3ff4c"] CGColor], nil]];
        [_borderLayer setLocations:@[@0,@1]];
        [_borderLayer setStartPoint:CGPointMake(0, 0)];
        [_borderLayer setEndPoint:CGPointMake(1, 0)];
        [_borderLayer setMask:progressLayer];
        [self.bgView.layer addSublayer:_borderLayer];
    }
    
    - (void)removeBorder {
        [_borderLayer removeFromSuperlayer];
        _borderLayer = nil;
    }
    

    相关文章

      网友评论

          本文标题:border渐变色(CAGradientLayer)

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