iOS assumes that converting a hexadecimal color to uicolor is useful

Source: Internet
Author: User

The UI gives a lot of time to developing hexadecimal color notation, and the program often uses Uicolor to convert it in the following way:

(Uicolor *) Rgbcolorfromhexstring: (NSString *) color alpha: (float) Alpha {//color value similar to #fffeee,alpha value similar to 1.0 for transparency int nums[6] = {0};for (int i = 1; i < [color length]; i++) {int temp = [Color characteratindex:i];if (temp >= ' 0 ' && temp <= ' 9 ') {nums[i-1] = [Color Characteratindex: I]-' 0 ';} else if (temp >= ' a ' && temp <= ' F ') {nums[i-1] = [color characteratindex:i]-' A ' + 10;} else if (temp >= ' a ' && temp <= ' f ') {nums[i-1] = [color characteratindex:i]-' a ' + 10;} else {return [Uicolor Whitecolor];}        } float RValue = (nums[0] * + nums[1])/255.0f;float Gvalue = (nums[2] *16 + nums[3])/255.0f;float BValue = (nums[4] * + nums[5])/255.0f; Uicolor *rgbcolor = [Uicolor colorwithred:rvalue green:gvalue blue:bvalue alpha:alpha];return RgbColor;}


iOS assumes that converting a hexadecimal color to uicolor is useful

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.