xixi

天空蓝缎带孔雀鱼- 我喜欢

弧形转圈圈 带渐变色

    UILabel *label = [[UILabel alloc] init];
    label.text = @"价";
    label.frame = CGRectMake(250, 450, 50, 50);
    label.textAlignment = NSTextAlignmentCenter;

    [self.view addSubview:label];
    
    CGPoint point = CGPointMake(label.frame.size.width/2, label.frame.size.width/2);

    //将贝塞尔曲线 调小一点点就好
    UIBezierPath *p = [UIBezierPath bezierPathWithArcCenter:point radius:24.0f startAngle:.0f endAngle:2*M_PI clockwise:YES];
    
    CAGradientLayer *_gl = [CAGradientLayer layer];
    _gl.frame = label.bounds;
    
    CAShapeLayer *backGroundLayer = [CAShapeLayer layer];
    backGroundLayer.fillColor = [UIColor clearColor].CGColor;
    backGroundLayer.strokeColor = [UIColor redColor].CGColor;
    backGroundLayer.lineCap = kCALineCapRound;
    backGroundLayer.lineJoin = kCALineJoinRound;
    backGroundLayer.path = p.CGPath;
    backGroundLayer.lineWidth = 1;
    backGroundLayer.frame = _gl.bounds;
    
    _gl.startPoint = CGPointMake(.0f, .5f);
    _gl.endPoint = CGPointMake(1.f, .5f);
    _gl.mask = backGroundLayer;
    
    //做出渐变色
    UIColor *ringColor = [UIColor redColor];
    NSMutableArray *colors = [NSMutableArray new];
    for(int i = 20; i >= 0; i-=2) {
        [colors addObject:(__bridge id)[ringColor colorWithAlphaComponent:i*.1f].CGColor];
    }
    _gl.colors = colors;
    
    [label.layer addSublayer:_gl];
    
    
    CABasicAnimation *animate = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    animate.byValue = @(M_PI*2);
    animate.duration = 1;
    animate.repeatCount = MAXFLOAT;
    [_gl addAnimation:animate forKey:@"animate"];

效果如下:


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/liwenjie0912/article/details/46804967
个人分类: IOS
上一篇类似 刷新的时候 那个转圈圈 动画
下一篇iOS valid architectures
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭