Skip to content

Commit 1e017e0

Browse files
committed
better color blending
1 parent d797840 commit 1e017e0

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

Classes/ios/UIColor+FlatUI.m

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,23 @@ + (UIColor *) asbestosColor {
117117
+ (UIColor *) blendedColorWithForegroundColor:(UIColor *)foregroundColor
118118
backgroundColor:(UIColor *)backgroundColor
119119
percentBlend:(CGFloat) percentBlend {
120-
121-
CGFloat onRed, offRed, newRed, onGreen, offGreen, newGreen, onBlue, offBlue, newBlue;
122-
[foregroundColor getRed:&onRed green:&onGreen blue:&onBlue alpha:nil];
123-
[backgroundColor getRed:&offRed green:&offGreen blue:&offBlue alpha:nil];
120+
CGFloat onRed, offRed, newRed, onGreen, offGreen, newGreen, onBlue, offBlue, newBlue, onWhite, offWhite;
121+
if ([foregroundColor getWhite:&onWhite alpha:nil]) {
122+
onRed = onWhite;
123+
onBlue = onWhite;
124+
onGreen = onWhite;
125+
}
126+
else {
127+
[foregroundColor getRed:&onRed green:&onGreen blue:&onBlue alpha:nil];
128+
}
129+
if ([backgroundColor getWhite:&offWhite alpha:nil]) {
130+
offRed = offWhite;
131+
offBlue = offWhite;
132+
offGreen = offWhite;
133+
}
134+
else {
135+
[backgroundColor getRed:&offRed green:&offGreen blue:&offBlue alpha:nil];
136+
}
124137
newRed = onRed * percentBlend + offRed * (1-percentBlend);
125138
newGreen = onGreen * percentBlend + offGreen * (1-percentBlend);
126139
newBlue = onBlue * percentBlend + offBlue * (1-percentBlend);

0 commit comments

Comments
 (0)