zoukankan      html  css  js  c++  java
  • ObjectC&&Swift 渐变色算法实现

    -(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;
    }
    

  • 相关阅读:
    关于 OpenSmtp 邮件标题过长后出现乱码问题的解决
    用于解析 sohu 新闻页面的 XSLT 文件
    CEGUI 0.7x实现下划线描边图文混排等效果
    Hash算法说明
    D3DXMatrixShadow 函数
    DLL动态链接库和LIB静态链接库之程序员经验分析
    printf格式控制符的完整格式(转载)
    深入说明HDR技术
    Irrlicht不定期分析
    8.3实例程序:平面阴影
  • 原文地址:https://www.cnblogs.com/shujucn/p/7481453.html
Copyright © 2011-2022 走看看