zoukankan      html  css  js  c++  java
  • 16进制字符串转换成UIColor,返回UIColor

    1.建立一个UIColor的category,命名为UIColor+Helper

    然后在UIColor+Helper.h中:

    //16进制字符串转换成UIColor,返回UIColor

    + (UIColor *)colorWithHexStr:(NSString *)colorStr;

    在UIColor+Helper.m中:

    //16进制字符串转换成UIColor

    + (UIColor *)colorWithHexStr:(NSString *)colorStr{

        NSString * redStr = [colorStr substringWithRange:NSMakeRange(0, 2)];

        NSScanner * redScanner = [NSScanner scannerWithString:redStr];

        unsigned int redIntValue;

        [redScanner scanHexInt:&redIntValue];

        

        NSString * greenStr = [colorStr substringWithRange:NSMakeRange(2, 2)];

        NSScanner * greenScanner = [NSScanner scannerWithString:greenStr];

        unsigned int greenIntValue;

        [greenScanner scanHexInt:&greenIntValue];

        

        NSString * blueStr = [colorStr substringWithRange:NSMakeRange(4, 2)];

        NSScanner * blueScanner = [NSScanner scannerWithString:blueStr];

        unsigned int blueIntValue;

        [blueScanner scanHexInt:&blueIntValue];

        

        return [UIColor colorWithRed:redIntValue/255.0 green:greenIntValue/255.0 blue:blueIntValue/255.0 alpha:1];

    }

     多数用于服务器后端传值,然后前端将16进制的色值展示出来

  • 相关阅读:
    数组方法的扩展,如map,reduce,fliter,forEach方法
    设计模式总体概括
    centos yum 安装 tomcat
    idea springboot 打包 war
    idea使用tomcat运行maven打包的war
    CentOS 7 用 yum 安装 Nginx
    CentOS更换yum源
    城市代码表mysql
    更改idea启动内存信息
    (三)多表代码生成
  • 原文地址:https://www.cnblogs.com/zhouyantongiOSDev/p/4371454.html
Copyright © 2011-2022 走看看