-(NSArray *)getGradIEntcolorWithStartcolor:(UIcolor *)startcolor endcolor:(UIcolor *)endcolor step:(NSInteger)step inverse:(BOol)inverse { //1 get start color rgb CGfloat startR = 0.0,startG = 0.0,startB = 0.0; CGcolorRef startcolorRGB = [startcolor CGcolor]; NSInteger startNumComponents = CGcolorGetNumberOfComponents(startcolorRGB); if (startNumComponents == 4) { const CGfloat *components = CGcolorGetComponents(startcolorRGB); startR = components[0]; startG = components[1]; startB = components[2]; } //2 get end color rgb CGfloat endR = 0.0,endG = 0.0,endB = 0.0; CGcolorRef endcolorRGB = [endcolor CGcolor]; NSInteger endNumComponents = CGcolorGetNumberOfComponents(endcolorRGB); if (endNumComponents == 4) { const CGfloat *components = CGcolorGetComponents(endcolorRGB); endR = components[0]; endG = components[1]; endB = components[2]; } //3 calculate total threshold by step CGfloat stepR = 0.0,stepG = 0.0,stepB = 0.0; stepR = step == 1 ? 0 : (endR-startR) / (step - 1); stepG = step == 1 ? 0 : (endG-startG) / (step - 1); stepB = step == 1 ? 0 : (endB-startB) / (step - 1); //calculate uicolor by step CGfloat green = startG; CGfloat red = startR; CGfloat blue = startB; NSMutableArray *stepcolorArray = [[NSMutableArray alloc] initWithCapacity:step]; for (NSInteger i = 0; i < step - 1; i++) { red = red + stepR; green = green + stepG; blue = green + stepB; UIcolor *color = [UIcolor colorWithRed:red green:green blue:blue Alpha:0]; [stepcolorArray addobject:color]; } return stepcolorArray;}总结
以上是内存溢出为你收集整理的ObjectC&&Swift 渐变色算法实现全部内容,希望文章能够帮你解决ObjectC&&Swift 渐变色算法实现所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)