給需要的朋友亡脑,思路還是比較簡(jiǎn)單邀跃,代碼比較直接拍屑,沒有封裝坑傅,復(fù)制粘貼即可看到效果唁毒。
屏幕快照 2017-01-09 下午4.00.58.png
- (void)creatText{
NSArray * colours = [NSArray arrayWithArray:[self getColoures]];
UIColor * colour0 = [UIColor new];
UIColor * colour1 = [UIColor new];
UIColor * colour2 = [UIColor new];
UIColor * colour3 = [UIColor new];
#pragma mark- gradientlayer 與 gradientlayer 之間顏色過渡
colour0 = colours[0];
colour1 = colours[1];
colour2 = colours[2];
colour3 = colours[3];
CALayer * layer0 = [CALayer layer];
layer0.frame = CGRectMake(20, 150, 150, 150);
[self.view.layer addSublayer:layer0];
CALayer * layer1 = [CALayer layer];
layer1.frame = CGRectMake(0, 0, 150, 150);
[layer0 addSublayer:layer1];
#pragma mark-4個(gè)gradientlayer顏色漸變
CAGradientLayer * gradientlayer1 = [CAGradientLayer layer];
gradientlayer1.frame = CGRectMake(0, 0, 75, 75);
gradientlayer1.colors = @[(__bridge id)colour0.CGColor,
(__bridge id)colour1.CGColor];
gradientlayer1.startPoint = CGPointMake(1, 0);
gradientlayer1.endPoint = CGPointMake(0, 1);
CAGradientLayer * gradientlayer2 = [CAGradientLayer layer];
gradientlayer2.frame = CGRectMake(0, 75, 75, 75);
gradientlayer2.colors = @[(__bridge id)colour1.CGColor,
(__bridge id)colour2.CGColor];
gradientlayer2.startPoint = CGPointMake(0, 0);
gradientlayer2.endPoint = CGPointMake(1,1);
CAGradientLayer * gradientlayer3 = [CAGradientLayer layer];
gradientlayer3.frame = CGRectMake(75, 75, 75, 75);
gradientlayer3.colors = @[(__bridge id)colour2.CGColor,
(__bridge id)colour3.CGColor];
gradientlayer3.startPoint = CGPointMake(0, 1);
gradientlayer3.endPoint = CGPointMake(1, 0);
CAGradientLayer * gradientlayer4 = [CAGradientLayer layer];
gradientlayer4.frame = CGRectMake(75, 0, 75, 75);
gradientlayer4.colors = @[(__bridge id)colour3.CGColor,
(__bridge id)[UIColor whiteColor].CGColor];
gradientlayer4.startPoint = CGPointMake(1, 1);
gradientlayer4.endPoint = CGPointMake(0, 0);
[layer1 addSublayer:gradientlayer1];
[layer1 addSublayer:gradientlayer2];
[layer1 addSublayer:gradientlayer3];
[layer1 addSublayer:gradientlayer4];
#pragma mark- 把下面代碼注釋掉粉私,就可以看到4個(gè)人gradientlayer顏色過渡效果
//路徑
UIBezierPath * beizierPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(75, 75) radius:70 startAngle: -M_PI/2 endAngle:M_PI*2 -M_PI/2 clockwise:YES];
CAShapeLayer * shaperLayer = [CAShapeLayer layer];
shaperLayer.lineCap = kCALineCapRound;
shaperLayer.fillColor = [UIColor clearColor].CGColor;
shaperLayer.strokeColor = [UIColor redColor].CGColor;
shaperLayer.lineWidth = 5.0;
shaperLayer.strokeStart = 0.01;
shaperLayer.strokeEnd = 0.99;
shaperLayer.path = beizierPath.CGPath;
layer1.mask = shaperLayer;
//添加動(dòng)畫
CABasicAnimation * basicAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
basicAnimation.duration = 1;
basicAnimation.fromValue = @0.0;
basicAnimation.toValue = @(M_PI*2);
basicAnimation.repeatCount = HUGE_VAL;
[layer0 addAnimation:basicAnimation forKey:@"transform.rotation.z"];
}
#pragma mark- 獲取顏色
- (NSArray *)getColoures{
NSMutableArray * array = [NSMutableArray new];
UIColor * redcolour = [UIColor colorWithHue:136.0 saturation:1.0 brightness:1.0 alpha:1];
//同一種顏色的不同飽和度(這里取4種)
for (int i = 0; i < 4; i++) {
CGFloat hue = 0.0;
CGFloat saturation = 0.0;
CGFloat brightness = 0.0;
CGFloat alpha = 0.0;
[redcolour getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha];
UIColor * newColour = [UIColor colorWithHue:hue saturation: saturation - (i*0.25) brightness:brightness alpha:alpha];
NSLog(@"%f,%f,%f,%f",hue,saturation,brightness,alpha);
[array addObject:newColour];
}
return array;
}