I have created a graph drawing points and creating a UIBezierPath between those points, but now I want to add a gradient to the plotted lines (similar to picture). The issue is I need a frame for the CAGradientLayer, which I do not know how to create given the plotted lines on a UIView. I have a stored array of CGPoint which contains all the points that are graphed, is there a way to create frame for the gradient with that array? Anyone know what to do here?
contains all points graphed
var graphedInvestedPoints = [CGPoint]()
func addGradient(){
let colorTop = UIColor(hexString: blueHexString)
let colorBottom = UIColor.white
let gradientLayer = CAGradientLayer()
gradientLayer.colors = [colorTop, colorBottom]
gradientLayer.locations = [0.0, 1.0]
//gradientLayer.frame = ?
self.layer.insertSublayer(gradientLayer, at: 0)
}


Here is one simple example, using a masked gradient layer.
Use your
graphedInvestedPointsto create the shape of the graph, apply that as the.pathproperty of aCAShapeLayerand then apply that layer as the.maskproperty of aCAGradientLayer:Output on a 240 x 240 view (the red dashed-outline is just there to show the frame of the view):