Hex color conversion to iOS can be used for Uicolor

Source: Internet
Author: User
Tags uikit

//

Uicolor+transformation.h

Contactapp

//

Created by Gongdongdong on 15/9/11.

Copyright (c) year Lan technology . All rights reserved.

//

#import <UIKit/UIKit.h>

@interface Uicolor (transformation)

+ (Uicolor *) Transformat: (NSString *) colorstring;

@end

//

Uicolor+transformation.m

Contactapp

//

Created by Gongdongdong on 15/9/11.

Copyright (c) year Lan technology . All rights reserved.

//

#import "Uicolor+transformation.h"

@implementation Uicolor (transformation)

+ (Uicolor *) Transformat: (NSString *) colorstring {

// Remove hex # For example (#FFFFFF)

NSString *newcolorstring = [colorstring substringfromindex:1];

Nsrange r1 = {0,2};

Nsrange r2 = {2,2};

Nsrange R3 = {4,2};

NSString *redstr = [newcolorstring substringwithrange:r1];

NSString *greenstr = [newcolorstring substringwithrange:r2];

NSString *bluestr = [newcolorstring SUBSTRINGWITHRANGE:R3];

Colorblock ([redstr substringtoindex:1]);

int red = [Colorblock ([Redstr substringtoindex:1]) intvalue] * + [Colorblock ([Redstr] Substringfromindex:1]) intvalue];

int green = [Colorblock ([Greenstr substringtoindex:1]) intvalue] * + [Colorblock ([Greenstr] Substringfromindex:1]) intvalue];

int blue = [Colorblock ([Bluestr substringtoindex:1]) intvalue] * + [Colorblock ([ Bluestr Substringfromindex:1]) intvalue];

float r = red/ 255.0;

float g = green/ 255.0;

float b = blue/ 255.0;

Uicolor *c = [Uicolor colorwithred:r green:g blue:b Alpha:1.0];

return C;

}

NSString * (^colorblock) (NSString *) = ^ (NSString *str) {

if([str isequaltostring:@ "A"]) {

str = @ "ten";

}Else if ([str isequaltostring:@ "B"]) {

str = @ "one";

}Else if ([str isequaltostring:@ "C"]) {

str = @ "n";

}

Else if ([str isequaltostring:@ "D"]) {

str = @ "+";

}

Else if ([str isequaltostring:@ "E"]) {

str = @ "+";

}Else if ([str isequaltostring:@ "F"]) {

str = @ "";

}

return str;

};

@end

Hex color conversion to iOS can be used for Uicolor

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.