Skip to content

Commit e4e913e

Browse files
jrapoportNeeeo
authored andcommitted
Add colorWithPatternImage support
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
1 parent 726ed5c commit e4e913e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

AWLThemeManager/AWLThemeManager.m

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ - (UIColor *)colorForKey:(NSString *)key forTheme:(NSString *)themeName
8686
}
8787

8888
NSString *colorValue = [self objectForKey:key forTheme:themeName];
89-
UIColor *color = [self colorFromString:colorValue];
89+
UIColor *color = [self colorFromString:colorValue forTheme: themeName];
9090
if (color == nil && [self isValidString:colorValue]) {
9191
NSArray* referenceColor = [colorValue componentsSeparatedByString:@":"];
9292
colorValue = referenceColor.firstObject;
@@ -99,9 +99,23 @@ - (UIColor *)colorForKey:(NSString *)key forTheme:(NSString *)themeName
9999
return color;
100100
}
101101

102-
- (UIColor*)colorFromString:(NSString*)colorValue
102+
- (UIColor*)colorFromString:(NSString*)colorValue forTheme:(NSString *)themeName
103103
{
104104
if ([self isValidString:colorValue]) {
105+
106+
if ([colorValue hasPrefix: @"#"]) {
107+
NSArray* array = [colorValue componentsSeparatedByString:@","];
108+
NSString* patternName = [array[0] substringFromIndex:1];
109+
UIImage* patternImage = [self imageNamed:patternName forTheme:themeName];
110+
if (patternImage == nil) {
111+
return nil;
112+
}
113+
UIColor* color = [UIColor colorWithPatternImage: patternImage];
114+
if (array.count == 2) {
115+
color = [color colorWithAlphaComponent: [array[1] doubleValue]];
116+
}
117+
return color;
118+
}
105119
NSArray* array = [colorValue componentsSeparatedByString:@","];
106120
if (array && [array count] == 2) {
107121
return [UIColor colorWithWhite:[array[0] doubleValue]

0 commit comments

Comments
 (0)