iOS tools 16 binary color to Uicolor

Source: Internet
Author: User

#define Default_void_color [Uicolor Whitecolor]
+ (Uicolor *) colorwithhexstring: (NSString *) stringtoconvert{nsstring *cstring = [[Stringtoconvert stringByTrimmingCha            Ractersinset:[nscharacterset Whitespaceandnewlinecharacterset]] uppercasestring];    if ([cString length] < 6) return default_void_color;    if ([CString hasprefix:@ "#"]) cString = [cString substringfromindex:1];        if ([cString length]! = 6) return default_void_color;    Nsrange range;    range.location = 0;    Range.length = 2;        NSString *rstring = [cString substringwithrange:range];    Range.location = 2;        NSString *gstring = [cString substringwithrange:range];    Range.location = 4;            NSString *bstring = [cString substringwithrange:range];    unsigned int r, G, B;    [[Nsscanner scannerwithstring:rstring] scanhexint:&r];    [[Nsscanner scannerwithstring:gstring] scanhexint:&g];        [[Nsscanner scannerwithstring:bstring] scanhexint:&b];  return [Uicolor colorwithred: ((float) r/255.0f)                         Green: ((float) g/255.0f) Blue: ((float) b/255.0f) ALPHA:1.0F];}

iOS tools 16 binary color to Uicolor

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.