IOS16 the color of the binary settings

Source: Internet
Author: User
Tags truncated uikit

Uicolor+hex.h

////uicolor+hex.h//16 Binary Color Categories////Created by Apple on 15-4-3.//Copyright (c) 2015 Apple. All rights reserved.//#import<UIKit/UIKit.h>#defineRgba_color (R, G, B, A) [Uicolor colorwithred: ((r)/255.0f) Green: ((G)/255.0f) Blue: ((B)/255.0f) ALPHA:A]#defineRgb_color (R, G, B) [Uicolor colorwithred: ((r)/255.0f) Green: ((G)/255.0f) Blue: ((B)/255.0f) alpha:1.0f]@interfaceUicolor (Hex)+ (Uicolor *) colorwithhexstring: (NSString *) color;//gets the color from the hexadecimal string,//Color: support @ "#123456", @ "0x123456", @ "123456" three formats+ (Uicolor *) colorwithhexstring: (NSString *) Color alpha: (cgfloat) Alpha;@end

Uicolor+hex.m

////UICOLOR+HEX.M//16 Binary Color Categories////Created by Apple on 15-4-3.//Copyright (c) 2015 Apple. All rights reserved.//#import "uicolor+hex.h"@implementationUicolor (Hex)+ (Uicolor *) colorwithhexstring: (NSString *) Color alpha: (cgfloat) alpha{//Delete spaces in a stringNSString *cstring =[[Color Stringbytrimmingcharactersinset:[nscharacterset Whitespaceandnewlinecharacterset]] uppercaseString]; //String should be 6 or 8 characters    if([cString Length] <6)    {        return[Uicolor Clearcolor]; }    //strip 0X If it appears//if it starts with 0x, then the string is truncated, and the string starts at the position indexed to 2, up to the end    if([cString Hasprefix:@"0X"]) {cString= [CString Substringfromindex:2]; }    //If it starts with #, then the string is truncated, and the string starts at the position indexed to 1, up to the end    if([cString Hasprefix:@"#"]) {cString= [CString Substringfromindex:1]; }    if([cString length]! =6)    {        return[Uicolor Clearcolor]; }        //separate into R, G, b substringsNsrange Range; Range.location=0; Range.length=2; //RNSString *rstring =[cString Substringwithrange:range]; //gRange.location =2; NSString*gstring =[cString Substringwithrange:range]; //bRange.location =4; NSString*bstring =[cString Substringwithrange:range]; //Scan ValuesUnsignedintR, 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:alpha];}//The default alpha value is 1+ (Uicolor *) colorwithhexstring: (NSString *) color{return[Self Colorwithhexstring:color Alpha:1.0f];}@end

IOS16 the color of the binary settings

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.