In iOS sometimes the UI gives a color number like #54e1b7 this, and we generally set the color is set according to RBG, so we need to put this 16-binary color number to the RGB value, here we use the method to call the set color.
1+ (Uicolor *) GetColor: (NSString *) Hexcolor2 {3 if(Hexcolor = = Nil | | hexcolor.length = =0) {4NSLog (@"The color string is nil.");5 return[Uicolor Blackcolor];6 }7UnsignedintRed,green,blue;8 Nsrange Range;9Range.length =2;Ten OneRange.location =0; ANSString *dehexcolor =[Hexcolor Substringwithrange:range]; -[[Nsscanner Scannerwithstring:dehexcolor] scanhexint:&Red]; - theRange.location =2; -Dehexcolor =[Hexcolor Substringwithrange:range]; -[[Nsscanner Scannerwithstring:dehexcolor] scanhexint:&Green]; - +Range.location =4; -Dehexcolor =[Hexcolor Substringwithrange:range]; +[[Nsscanner Scannerwithstring:dehexcolor] scanhexint:&Blue]; A at return[Uicolor colorwithred: (float) (red/255.0f) Green: (float) (Green/255.0f) Blue: (float) (Blue/255.0f) Alpha:1.0f]; -}
iOS sets the color based on the 16-in color number, which is suitable for encapsulating tool classes