From b45a44be2aa510bd6597b053d986d493995b8c41 Mon Sep 17 00:00:00 2001 From: Simon Fairbairn Date: Sun, 30 Jun 2013 14:04:39 -0500 Subject: [PATCH 1/3] Adding support for alpha (searches for xAlpha, defaults to 1.0f) --- Source/VSTheme.m | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Source/VSTheme.m b/Source/VSTheme.m index ca8056e..3e4023f 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,8 @@ - (UIColor *)colorForKey:(NSString *)key { return cachedColor; NSString *colorString = [self stringForKey:key]; - UIColor *color = colorWithHexString(colorString); + NSNumber *number = [NSNumber numberWithFloat:[self floatForKey:[NSString stringWithFormat:@"%@Alpha", key]]]; + UIColor *color = colorWithHexString(colorString, number); if (color == nil) color = [UIColor blackColor]; @@ -262,8 +263,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)) From 0d40879d634a79636a3113eb79d216d0f1a9f749 Mon Sep 17 00:00:00 2001 From: Simon Fairbairn Date: Sun, 30 Jun 2013 14:07:31 -0500 Subject: [PATCH 2/3] Forgot to add variable to UIColor message --- Source/VSTheme.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/VSTheme.m b/Source/VSTheme.m index 3e4023f..9ef9c6e 100644 --- a/Source/VSTheme.m +++ b/Source/VSTheme.m @@ -291,5 +291,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]; } From ed35522cd838a5e21c9a1bff37d203781d8bdf35 Mon Sep 17 00:00:00 2001 From: Simon Fairbairn Date: Sun, 30 Jun 2013 14:16:24 -0500 Subject: [PATCH 3/3] Fixing issue with nil values --- Source/VSTheme.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/VSTheme.m b/Source/VSTheme.m index 9ef9c6e..d7a48d9 100644 --- a/Source/VSTheme.m +++ b/Source/VSTheme.m @@ -117,7 +117,12 @@ - (UIColor *)colorForKey:(NSString *)key { return cachedColor; NSString *colorString = [self stringForKey:key]; - NSNumber *number = [NSNumber numberWithFloat:[self floatForKey:[NSString stringWithFormat:@"%@Alpha", key]]]; + 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];