美文网首页
CAGradientLayer实现圆环的颜色渐变

CAGradientLayer实现圆环的颜色渐变

作者: 萧过 | 来源:发表于2016-08-09 11:46 被阅读0次
    效果图

    函数代码:

    #pragma mark彩色的圆

    -(void)recordingCircleOverlayView

    {

    self.backgroundColor=[UIColorpurpleColor];

    //根图层

    CALayer*thelayer=[CALayerlayer];

    thelayer.frame=CGRectMake(0,0,CGRectGetWidth(self.frame)/2.,CGRectGetWidth(self.frame)/2.);

    thelayer.backgroundColor=[UIColorwhiteColor].CGColor;

    [self.layeraddSublayer:thelayer];

    //画圆

    UIBezierPath*theCirclePath1=[UIBezierPathbezierPathWithArcCenter:CGPointMake(thelayer.position.x, thelayer.position.y)radius:90startAngle:M_PIendAngle:-M_PIclockwise:NO];

    CAShapeLayer*theBigLayer=[CAShapeLayerlayer];

    theBigLayer.path=theCirclePath1.CGPath;

    theBigLayer.strokeColor=[UIColorpurpleColor].CGColor;

    theBigLayer.fillColor=[UIColorclearColor].CGColor;

    theBigLayer.lineWidth=5;

    theBigLayer.strokeStart=0;

    //分块颜色

    CAGradientLayer*theGradien=[CAGradientLayerlayer];

    theGradien.frame=thelayer.bounds;

    theGradien.colors=@[

    (__bridgeid)[UIColoryellowColor].CGColor,

    (__bridgeid)[UIColorredColor].CGColor,

    (__bridgeid)[UIColorblueColor].CGColor

    ];

    theGradien.locations=@[@.25,@.5,@.8];

    [thelayeraddSublayer:theGradien];

    //遮罩

    thelayer.mask=theBigLayer;

    //动画

    CABasicAnimation*baseAnim=[CABasicAnimationanimationWithKeyPath:@"strokeStart"];

    baseAnim.fromValue=[NSNumbernumberWithFloat:0.];

    baseAnim.toValue=[NSNumbernumberWithFloat:1.];

    baseAnim.duration=5;

    baseAnim.repeatCount=9;

    [theBigLayeraddAnimation:baseAnimforKey:@"stro"];

    }

    相关文章

      网友评论

          本文标题:CAGradientLayer实现圆环的颜色渐变

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