iOS If you convert a hexadecimal color to uicolor, it's useful

Source: Internet
Author: User

The UI gives the development a lot of time to mark the hexadecimal color, and the application is often uicolor can be converted in the following ways:

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


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.