Closed AlexNolasco closed 9 years ago
+1
Unfortunately, this project seems to be abandoned.
No it's not! I'm going to check the implementaiton today!
Is https://github.com/mRs-/HexColors/pull/9 exactly what you want?
We're using #9 on our production code and it works great. ;-)
ok sounds cool. Then I will create a new version today! With an Pod update!
It's done
for example
(HXColor )colorWithAlphaHexString:(NSString )hexString { // Check for hash and add the missing hash. E.g. # 80 FF FF FF if('#' != [hexString characterAtIndex:0]) { hexString = [NSString stringWithFormat:@"#%@", hexString]; }
// check for string length assert(9 == hexString.length );
NSString *alpha = [NSString stringWithFormat:@"0x%@", [hexString substringWithRange:NSMakeRange(1, 2)]]; float alphaFloat = [[self class] hexValueToFloat:alpha];
NSString *redHex = [NSString stringWithFormat:@"0x%@", [hexString substringWithRange:NSMakeRange(3, 2)]]; unsigned redInt = [[self class] hexValueToUnsigned:redHex];
NSString *greenHex = [NSString stringWithFormat:@"0x%@", [hexString substringWithRange:NSMakeRange(5, 2)]]; unsigned greenInt = [[self class] hexValueToUnsigned:greenHex];
NSString *blueHex = [NSString stringWithFormat:@"0x%@", [hexString substringWithRange:NSMakeRange(7, 2)]]; unsigned blueInt = [[self class] hexValueToUnsigned:blueHex];
HXColor *color = [HXColor colorWith8BitRed:redInt green:greenInt blue:blueInt alpha:alphaFloat];
return color; }
(CGFloat)hexValueToFloat:(NSString )hexValue { float value = 0.0; NSScanner hexValueScanner = [NSScanner scannerWithString:hexValue]; [hexValueScanner scanFloat:&value];
return value; }