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