Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for RGBA hex string #48

Closed
vitorhugomagalhaes opened this issue Nov 12, 2015 · 2 comments
Closed

Support for RGBA hex string #48

vitorhugomagalhaes opened this issue Nov 12, 2015 · 2 comments

Comments

@vitorhugomagalhaes
Copy link

Hi,

First of all, great library :)

I realised that there is no support for RGBA hex string although, with the following code it should be easy to support it.

+ (UIColor*) iss_colorWithHexString:(NSString*)hex {
    hex = [hex iss_trim];
    if ( hex.length == 6 ) {
        NSScanner* scanner = [NSScanner scannerWithString:hex];
        unsigned int cc = 0;

        if( [scanner scanHexInt:&cc] ) {
            NSInteger r = (cc >> 16) & 0xFF;
            NSInteger g = (cc >> 8) & 0xFF;
            NSInteger b = cc & 0xFF;
            return [self iss_colorWithR:r G:g B:b];
        }
    } else if ( hex.length == 8 ) {
        NSScanner* scanner = [NSScanner scannerWithString:hex];
        unsigned int cc = 0;

        if( [scanner scanHexInt:&cc] ) {
            NSInteger r = (cc >> 24) & 0xFF;
            NSInteger g = (cc >> 16) & 0xFF;
            NSInteger b = (cc >> 8)  & 0xFF;
            NSInteger a = cc & 0xFF;
            return [self iss_colorWithR:r G:g B:b A:a];
        }
    }
    return [UIColor magentaColor];
}

Could you integrate it into the master branch or do you want me to raise a pull request ?

BR,

@tolo tolo closed this as completed in 5c8a0e4 Nov 13, 2015
@tolo
Copy link
Owner

tolo commented Nov 13, 2015

Thanks! :)

Great suggestion - I've added support for alpha component in hex strings now, and also support for compact hex strings (3 or 4 hex digits, 4 bits per channel).

Cheers,
Tobias

@vitorhugomagalhaes
Copy link
Author

Great !

Thanks for the quick feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants