Currently set Uicolor in iOS can only use its enumeration values, RGB and other methods, can not directly convert the commonly used 16 color value directly into the Uicolor object, so write a point code, the 16 color value into Uicolor.
Code as follows,
Header file
#import <Foundation/Foundation.h>#import <UIKit/UIKit.h>@interface Textservcie:nsobject+ (Uicolor *) Getcolorfromhex: (NSString *) hex; @end
. m
#import "TextServcie.h"@implementationTextservcie+ (Uicolor *) Getcolorfromhex: (NSString *) hex{Hex= [[Hex uppercasestring] Substringfromindex:1]; CGFloat valuearray[3]; Nsarray*strarray=[nsarray Arraywithobjects:[hex Substringwithrange:nsmakerange (0,2)],[hex Substringwithrange:nsmakerange (2,2)],[hex Substringwithrange:nsmakerange (4,2)], nil]; for(intI=0; i<strarray.count;i++) {hex=Strarray[i]; CGFloat value= ([Hex characteratindex:0]-'A'+Ten)*16.0f+[hex Characteratindex:1]-'A'+Ten; Valuearray[i]=value; } return[Uicolor colorwithred:valuearray[0]/255green:valuearray[1]/255blue:valuearray[2]/255Alpha1];}@end
The above code, working properly, next time no more tools to manually turn RGB
iOS development-Get uicolor from 16 binary colors