十六进制颜色改为RGB颜色,RGB颜色转为十六进制

1、 十六进制颜色改为 RGB 颜色  
+ ( UIColor  *)getRGBColorWithHexadecimalString:( NSString  *)hexaDecimal withAlpha:( CGFloat )alpha{
     if  (hexaDecimal. length  >  6 ) {
        hexaDecimal = [hexaDecimal  substringFromIndex :hexaDecimal. length  -  6 ];
    }
     if  (hexaDecimal && hexaDecimal. length  ==  6 ) {
         NSString  *strOne = [ NSString   stringWithFormat : @"%ld" , strtoul ([[hexaDecimal substringWithRange : NSMakeRange ( 0 2 )]  UTF8String ],  0 16 )];
         NSString  *strTwo = [ NSString   stringWithFormat : @"%ld" , strtoul ([[hexaDecimal substringWithRange : NSMakeRange ( 2 2 )]  UTF8String ],  0 16 )];
         NSString  *strThree = [ NSString   stringWithFormat : @"%ld" , strtoul ([[hexaDecimal substringWithRange : NSMakeRange ( 4 2 )]  UTF8String ],  0 16 )];
         return   RGB ([strOne floatValue], [strTwo floatValue], [strThree floatValue], alpha);
    }
     return   RGB ( 255.0 255.0 255.0 1.0 );
}
2、RGB 颜色转为十六进制
+ ( NSString  *)getHexadecimalStringWithRGBValue:( NSInteger )rgbValue{
     if  (rgbValue >  255  || rgbValue <  0 ) {
         return   @"00" ;
    }
     NSString  *hexadecimalStr = [[ NSString   stringWithFormat : @"%02lx" ,( long )rgbValue]  uppercaseString ];
     return  hexadecimalStr?hexadecimalStr: @"00" ;
}

你可能感兴趣的:(十六进制颜色改为RGB颜色,RGB颜色转为十六进制)