From 2237ee843664d50f2d10f78b801b9029abf7ff24 Mon Sep 17 00:00:00 2001 From: "Xinlei(Ryan) Pan" Date: Wed, 15 Jan 2020 15:34:16 -0500 Subject: [PATCH 1/2] update color --- MVMCoreUI/Atoms/Views/GraphView.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/GraphView.swift b/MVMCoreUI/Atoms/Views/GraphView.swift index cda77660..1f6ea45b 100644 --- a/MVMCoreUI/Atoms/Views/GraphView.swift +++ b/MVMCoreUI/Atoms/Views/GraphView.swift @@ -112,7 +112,9 @@ import UIKit //if number of colors is even, need to display gradient layer, otherwise make top layer as solid color layer if graphObject.colors.count % 2 == 0 { leftColors.removeLast() - topLayer.colors = [leftColors.last!, rightColors.first!] + let firstColor = leftColors.last!.uiColor.cgColor + let secondColor = rightColors.first!.uiColor.cgColor + topLayer.colors = [firstColor, secondColor] } else { topLayer.backgroundColor = leftColors.last?.uiColor.cgColor } @@ -125,7 +127,9 @@ import UIKit //count of graidentLayer.colors must be bigger than 1, otherwise set backgroundColor if leftColors.count > 1 { - leftLayer.colors = Array(leftColors) + leftLayer.colors = leftColors.map({ (color) -> CGColor in + return color.uiColor.cgColor + }) } else { leftLayer.backgroundColor = leftColors.first?.uiColor.cgColor } @@ -136,7 +140,9 @@ import UIKit rightLayer.startPoint = CGPoint(x: 0, y: 0) rightLayer.endPoint = CGPoint(x: 0, y: 1) if rightColors.count > 1 { - rightLayer.colors = Array(rightColors) + rightLayer.colors = rightColors.map({ (color) -> CGColor in + return color.uiColor.cgColor + }) } else { rightLayer.backgroundColor = rightColors.first?.uiColor.cgColor } From 5d1ef7161dbb20a9dab420effd94c290b5077461 Mon Sep 17 00:00:00 2001 From: "Xinlei(Ryan) Pan" Date: Wed, 15 Jan 2020 17:03:09 -0500 Subject: [PATCH 2/2] update to cgcolor directly --- MVMCoreUI/Atoms/Views/GraphView.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/GraphView.swift b/MVMCoreUI/Atoms/Views/GraphView.swift index 1f6ea45b..cc45433d 100644 --- a/MVMCoreUI/Atoms/Views/GraphView.swift +++ b/MVMCoreUI/Atoms/Views/GraphView.swift @@ -95,7 +95,7 @@ import UIKit //create graident layers guard graphObject.colors.count > 1 else { - containLayer.backgroundColor = graphObject.colors.first?.uiColor.cgColor + containLayer.backgroundColor = graphObject.colors.first?.cgColor return containLayer } var topGradientHeight : CGFloat = 0.0 @@ -112,11 +112,11 @@ import UIKit //if number of colors is even, need to display gradient layer, otherwise make top layer as solid color layer if graphObject.colors.count % 2 == 0 { leftColors.removeLast() - let firstColor = leftColors.last!.uiColor.cgColor - let secondColor = rightColors.first!.uiColor.cgColor + let firstColor = leftColors.last!.cgColor + let secondColor = rightColors.first!.cgColor topLayer.colors = [firstColor, secondColor] } else { - topLayer.backgroundColor = leftColors.last?.uiColor.cgColor + topLayer.backgroundColor = leftColors.last?.cgColor } containLayer.addSublayer(topLayer) @@ -128,10 +128,10 @@ import UIKit //count of graidentLayer.colors must be bigger than 1, otherwise set backgroundColor if leftColors.count > 1 { leftLayer.colors = leftColors.map({ (color) -> CGColor in - return color.uiColor.cgColor + return color.cgColor }) } else { - leftLayer.backgroundColor = leftColors.first?.uiColor.cgColor + leftLayer.backgroundColor = leftColors.first?.cgColor } containLayer.addSublayer(leftLayer) @@ -141,10 +141,10 @@ import UIKit rightLayer.endPoint = CGPoint(x: 0, y: 1) if rightColors.count > 1 { rightLayer.colors = rightColors.map({ (color) -> CGColor in - return color.uiColor.cgColor + return color.cgColor }) } else { - rightLayer.backgroundColor = rightColors.first?.uiColor.cgColor + rightLayer.backgroundColor = rightColors.first?.cgColor } containLayer.addSublayer(rightLayer)