iOS sets the color based on the 16-in color number, which is suitable for encapsulating tool classes

Source: Internet
Author: User

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

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.