W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
- (UIColor *)transformFromColor:(UIColor*)fromColor toColor:(UIColor *)toColor progress:(CGFloat)progress {
progress = progress >= 1 ? 1 : progress;
progress = progress <= 0 ? 0 : progress;
const CGFloat * fromeComponents = CGColorGetComponents(fromColor.CGColor);
const CGFloat * toComponents = CGColorGetComponents(toColor.CGColor);
size_t fromColorNumber = CGColorGetNumberOfComponents(fromColor.CGColor);
size_t toColorNumber = CGColorGetNumberOfComponents(toColor.CGColor);
if (fromColorNumber == 2) {
CGFloat white = fromeComponents[0];
fromColor = [UIColor colorWithRed:white green:white blue:white alpha:1];
fromeComponents = CGColorGetComponents(fromColor.CGColor);
}
if (toColorNumber == 2) {
CGFloat white = toComponents[0];
toColor = [UIColor colorWithRed:white green:white blue:white alpha:1];
toComponents = CGColorGetComponents(toColor.CGColor);
}
CGFloat r = fromeComponents[0]*(1 - progress) + toComponents[0]*progress;
CGFloat g = fromeComponents[1]*(1 - progress) + toComponents[1]*progress;
CGFloat b = fromeComponents[2]*(1 - progress) + toComponents[2]*progress;
return [UIColor colorWithRed:r green:g blue:b alpha:1];
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: