0
现在我有这个代码,我希望能够随着弧的角度变化逐渐改变颜色。如何在Objective-C和Swift中使用UIColor逐渐改变颜色?
我想逐渐从绿色变为黄色,然后是橙色,然后是红色。但逐渐地,不只是一次。
有关如何做到这一点的任何想法?
UIColor *greenColor = [UIColor greenColor];
greenColor = [UIColor colorWithRed:.0 green:1 blue:.0 alpha:0.5];
UIColor *grayColor = [UIColor grayColor];
grayColor = [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:0.5];
UIColor *redColor = [UIColor redColor];
redColor = [UIColor colorWithRed:1.0 green:.0 blue:.0 alpha:0.5];
UIColor *yellowColor = [UIColor yellowColor];
yellowColor = [UIColor colorWithRed:1.0 green:1.0 blue:.0 alpha:0.5];
UIColor *orangeColor = [UIColor orangeColor];
orangeColor = [UIColor colorWithRed:1.0 green:0.647 blue:.0 alpha:0.5];
int direction = 0;
if(index == 3){
direction = 1;
CGFloat currentEndAngle = atan2f(d_y, d_x);
CGFloat actualEndAngle = -0.49234065359; //was M_PI
if(fabs(currentEndAngle*180/M_PI) <= 91){
// Draw the optimal arc
//[self drawArc:ourPoint.startPosition andEndAngle:actualEndAngle andRadius:radius andColor:grayColor andDirection:direction withContext:context];
if(currentEndAngle > 0 || currentEndAngle > actualEndAngle){
// Draw the current green arc
if(currentEndAngle - actualEndAngle < 0.6){
[self drawArc:ourPoint.startPosition andEndAngle:currentEndAngle andRadius:radius andColor:orangeColor andDirection:direction withContext:context];
}
else{
[self drawArc:ourPoint.startPosition andEndAngle:currentEndAngle andRadius:radius andColor:greenColor andDirection:direction withContext:context];
}
}
else{
// Draw the current red arc
[self drawArc:ourPoint.startPosition andEndAngle:currentEndAngle andRadius:radius andColor:redColor andDirection:direction withContext:context];
missAngle += fabs(currentEndAngle-actualEndAngle);
}
}
请删除您的swift标签。这不是快速代码... – Anokrize