zoukankan      html  css  js  c++  java
  • 16进制转rgb

    - (void)colorWithHexString: (NSString *) stringToConvert

     {

             //去掉前后空格换行符

             NSString *cString = [[stringToConvert stringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceAndNewlineCharacterSet]] uppercaseString];

        

                           

               if ([cString hasPrefix:@"0X"])

                     cString = [cString substringFromIndex:2];

             else if ([cString hasPrefix:@"#"])

                     cString = [cString substringFromIndex:1];

        

            

                 

                

        

             // Separate into r, g, b substrings

             NSRange range;

             range.location = 0;

             range.length = 2;

             NSString *rString = [cString substringWithRange:range];

        

             range.location = 2;

             NSString *gString = [cString substringWithRange:range];

        

             range.location = 4;

             NSString *bString = [cString substringWithRange:range];

        

             unsigned int r, g, b;

             [[NSScanner scannerWithString:rString] scanHexInt:&r];

             [[NSScanner scannerWithString:gString] scanHexInt:&g];

             [[NSScanner scannerWithString:bString] scanHexInt:&b];

             NSLog(@"r = %u, g = %u, b = %u",r, g, b);

             

         }

  • 相关阅读:
    CORS enabled image (Miscellaneous) – HTML 中文开发手册
    PHP fread() 函数
    iswcntrl (Strings) – C 中文开发手册
    HTML DOM createComment() 方法
    HTML draggable 事件属性
    HTML table border 属性
    dedecms开启多站点
    SVN中trunk,branches,tags用法详解
    docker:搭建lamp应用
    centos安装samba
  • 原文地址:https://www.cnblogs.com/sgdkg/p/3156682.html
Copyright © 2011-2022 走看看