1. If the color string data returned from the server is
Hexcolor: "B57A"
Hexcolor is divided into three parts: 09, B5, 7A respectively corresponding to the tri-color value R, G, B
| Hexadecimal |
Decimal |
| 00 |
0 |
| 01 |
1 |
| ... |
... |
| 09 |
9 |
| 0A |
10 |
| 0B |
11 |
| ... |
... |
| 0F |
15 |
| 10 |
16 |
| 11 |
17 |
| 12 |
18 |
| ... |
... |
| 1F |
31 |
| ... |
|
| Ff |
255 |
|
|
|
|
The code is as follows:
1-(Uicolor *) GetColor: (NSString *) Hexcolor2 {3UnsignedintRed,green,blue;4 Nsrange Range;5Range.length =2;6 7 //capturing the red part8Range.location =0;9[[Nsscanner Scannerwithstring:[hexcolor Substringwithrange:range]] scanhexint:&Red];Ten One //Intercept Green Section ARange.location =2; -[[Nsscanner Scannerwithstring:[hexcolor Substringwithrange:range]] scanhexint:&Green]; - the //intercept the blue section -Range.location =4; -[[Nsscanner Scannerwithstring:[hexcolor Substringwithrange:range]] scanhexint:&Blue]; - + returnRgbColor (red, green, blue,1.0); -}