From 137b6e24c48f2d2a9bae05f91027a5b8725e5ddd Mon Sep 17 00:00:00 2001 From: Frederik Lipfert Date: Sat, 28 Feb 2015 18:58:28 +0100 Subject: [PATCH 1/2] Fixed progressBarTo Issue Adjusting the height of a bar with cashapelayers by covering up what was there, not everything was covered, leaving behind artifacts. This is due to the rendering of uneven float numbers. I changed it so only full and half pixels are used. --- Source/BarGraph/GKBar.m | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Source/BarGraph/GKBar.m b/Source/BarGraph/GKBar.m index d445dd8..eccfa2a 100644 --- a/Source/BarGraph/GKBar.m +++ b/Source/BarGraph/GKBar.m @@ -95,13 +95,13 @@ - (void)setPercentage:(CGFloat)percentage { _percentage = percentage; } -- (void)_progressBarTo:(CGFloat)value { - - CGFloat converted = (value / 100); +- (void)_progressBarTo:(CGFloat)value +{ + CGFloat converted = (value < 0.5f ? 0.0f : floorf(value * 2) / 2 / 100); UIBezierPath *path = [self _bezierPathWith:converted]; CAShapeLayer *layer = [self _layerWithPath:path]; - if (_percentage > value) layer.strokeColor = [self.backgroundColor CGColor]; + if (_percentage > value) layer.strokeColor = [[UIColor whiteColor] CGColor]; [self.layer addSublayer:layer]; @@ -114,10 +114,12 @@ - (void)_progressBarTo:(CGFloat)value { - (UIBezierPath *)_bezierPathWith:(CGFloat)value { UIBezierPath *path = [UIBezierPath bezierPath]; CGFloat startX = (self.frame.size.width / 2); - CGFloat startY = (self.frame.size.height * (1 - (_percentage / 100))); - CGFloat endY = (self.frame.size.height * (1 - value)); + CGFloat startY0 = (self.frame.size.height * (1 - (_percentage / 100))); + CGFloat startY = startY0 < 0.5f ? 0.0f : floorf(startY0 * 2) / 2; + CGFloat endY0 = (self.frame.size.height * (1 - value)); + CGFloat endY = endY0 < 0.5f ? 0.0f : floorf(endY0 * 2) / 2; [path moveToPoint:CGPointMake(startX, startY)]; - [path addLineToPoint:CGPointMake(startX, endY)]; + [path addLineToPoint:CGPointMake(startX, endY)]; return path; } From a0b58e046f43b941f6b4cfb9e185f9589b60ed15 Mon Sep 17 00:00:00 2001 From: Frederik Lipfert Date: Sat, 28 Feb 2015 19:02:48 +0100 Subject: [PATCH 2/2] Corrected Color --- Source/BarGraph/GKBar.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/BarGraph/GKBar.m b/Source/BarGraph/GKBar.m index eccfa2a..4aa801d 100644 --- a/Source/BarGraph/GKBar.m +++ b/Source/BarGraph/GKBar.m @@ -101,7 +101,7 @@ - (void)_progressBarTo:(CGFloat)value UIBezierPath *path = [self _bezierPathWith:converted]; CAShapeLayer *layer = [self _layerWithPath:path]; - if (_percentage > value) layer.strokeColor = [[UIColor whiteColor] CGColor]; + if (_percentage > value) layer.strokeColor = [self.backgroundColor CGColor]; [self.layer addSublayer:layer];