diff --git a/Source/VSTheme.m b/Source/VSTheme.m index ca8056e..d7a48d9 100644 --- a/Source/VSTheme.m +++ b/Source/VSTheme.m @@ -10,7 +10,7 @@ static BOOL stringIsEmpty(NSString *s); -static UIColor *colorWithHexString(NSString *hexString); +static UIColor *colorWithHexString(NSString *hexString, NSNumber *alpha); @interface VSTheme () @@ -117,7 +117,13 @@ - (UIColor *)colorForKey:(NSString *)key { return cachedColor; NSString *colorString = [self stringForKey:key]; - UIColor *color = colorWithHexString(colorString); + NSNumber *number; + if ( [self objectForKey:[NSString stringWithFormat:@"%@Alpha", key]]) { + number = [NSNumber numberWithFloat:[self floatForKey:[NSString stringWithFormat:@"%@Alpha", key]]]; + } + + + UIColor *color = colorWithHexString(colorString, number); if (color == nil) color = [UIColor blackColor]; @@ -262,8 +268,16 @@ static BOOL stringIsEmpty(NSString *s) { } -static UIColor *colorWithHexString(NSString *hexString) { +static UIColor *colorWithHexString(NSString *hexString, NSNumber *alpha) { + float a = 1.0f; + if ( alpha ) { + a = [alpha floatValue]; + } + if ( a > 1.0f || a < 0.0f ) { + a = 1.0f; + } + /*Picky. Crashes by design.*/ if (stringIsEmpty(hexString)) @@ -282,5 +296,5 @@ static BOOL stringIsEmpty(NSString *s) { [[NSScanner scannerWithString:greenString] scanHexInt:&green]; [[NSScanner scannerWithString:blueString] scanHexInt:&blue]; - return [UIColor colorWithRed:(CGFloat)red/255.0f green:(CGFloat)green/255.0f blue:(CGFloat)blue/255.0f alpha:1.0f]; + return [UIColor colorWithRed:(CGFloat)red/255.0f green:(CGFloat)green/255.0f blue:(CGFloat)blue/255.0f alpha:a]; }