Hex color data for iOS development converted to Uicolor object

Source: Internet
Author: User

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); -}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.