Skip to content

Commit

Permalink
Add colorWithPatternImage support
Browse files Browse the repository at this point in the history
Now if you specify as color as “#[ImageName]” it will search for the
“Foo” image using the usual methods & if found, return a color using
that image as a pattern. To change the alpha, use
“#[ImageName],[Alpha]” e.g. #Foo,0.3
  • Loading branch information
jrapoport committed Mar 2, 2016
1 parent be992cb commit 63c7e3f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions AWLThemeManager/AWLThemeManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ - (UIColor *)colorForKey:(NSString *)key forTheme:(NSString *)themeName
}

NSString *colorValue = [self objectForKey:key forTheme:themeName];
UIColor *color = [self colorFromString:colorValue];
UIColor *color = [self colorFromString:colorValue forTheme: themeName];
if (color == nil && [self isValidString:colorValue]) {
NSArray* referenceColor = [colorValue componentsSeparatedByString:@":"];
colorValue = referenceColor.firstObject;
Expand All @@ -116,9 +116,23 @@ - (UIColor *)colorForKey:(NSString *)key forTheme:(NSString *)themeName
return color;
}

- (UIColor*)colorFromString:(NSString*)colorValue
- (UIColor*)colorFromString:(NSString*)colorValue forTheme:(NSString *)themeName
{
if ([self isValidString:colorValue]) {

if ([colorValue hasPrefix: @"#"]) {
NSArray* array = [colorValue componentsSeparatedByString:@","];
NSString* patternName = [array[0] substringFromIndex:1];
UIImage* patternImage = [self imageNamed:patternName forTheme:themeName];
if (patternImage == nil) {
return nil;
}
UIColor* color = [UIColor colorWithPatternImage: patternImage];
if (array.count == 2) {
color = [color colorWithAlphaComponent: [array[1] doubleValue]];
}
return color;
}
NSArray* array = [colorValue componentsSeparatedByString:@","];
if (array && [array count] == 2) {
return [UIColor colorWithWhite:[array[0] doubleValue]
Expand Down

0 comments on commit 63c7e3f

Please sign in to comment.