All, I got the code to create a pie chart based on a number entered. The pie segments of CAShapeLayers are equal segments of the pie. that all gets laid out correctly. Now I'm trying to get the number of the segment into the center of the pie segment. For example a circle equally divided into 4 segments, and each segment is numbered 1, 2, 3 and 4.
Yet the text never displays or shows. I've commented out the CATextLayer code as it's not working. I can't figure out what is wrong or why the text number isn't being displayed.
here's the code:
As always any help is appreciated.
Thanks for any suggestions/help
Matt P.
Yet the text never displays or shows. I've commented out the CATextLayer code as it's not working. I can't figure out what is wrong or why the text number isn't being displayed.
here's the code:
As always any help is appreciated.
Code Block language var CircleEndAngle = (CGFloat.pi*2)/CGFloat(Number) var circlePath = UIBezierPath(arcCenter: Center, radius: CGFloat(DeviceRadius), startAngle: CircleStartAngle, endAngle: CircleEndAngle, clockwise: true) circlePath.addLine(to: view.center) circlePath.close() //let TextNum = CATextLayer() while i < Number { circlePath = UIBezierPath(arcCenter: Center, radius: CGFloat(DeviceRadius), startAngle: CircleStartAngle, endAngle: CircleEndAngle, clockwise: true) circlePath.addLine(to: view.center) circlePath.close() let shapeLayer = CAShapeLayer() //let TextNum = CATextLayer() shapeLayer.lineWidth = 3.0 if Number > 50 { shapeLayer.strokeColor = UIColor.black.cgColor } else { shapeLayer.strokeColor = UIColor.white.cgColor } if LoopCounter > 10 { LoopCounter = 0 CycleColorArrayIndex = 1 } switch CycleColorArrayIndex { case 0: shapeLayer.fillColor = UIColor.red.cgColor case 1: shapeLayer.fillColor = UIColor.blue.cgColor case 2: shapeLayer.fillColor = UIColor.green.cgColor case 3: shapeLayer.fillColor = UIColor.purple.cgColor case 4: shapeLayer.fillColor = UIColor.cyan.cgColor case 5: shapeLayer.fillColor = UIColor.black.cgColor case 6: shapeLayer.fillColor = UIColor.magenta.cgColor case 7: shapeLayer.fillColor = UIColor.brown.cgColor case 8: shapeLayer.fillColor = UIColor.yellow.cgColor case 9: shapeLayer.fillColor = UIColor.orange.cgColor case 10: shapeLayer.fillColor = UIColor.darkGray.cgColor default: shapeLayer.fillColor = UIColor.gray.cgColor } shapeLayer.path = circlePath.cgPath //TextNum.string = "\(i)" //shapeLayer.addSublayer(TextNum) ShapeLayers.append(shapeLayer) i = i+1 CircleStartAngle = CircleEndAngle CircleEndAngle = CircleStartAngle + ((CGFloat.pi*2)/(CGFloat(Number))) circlePath = UIBezierPath(arcCenter: Center, radius: CGFloat(DeviceRadius), startAngle: CircleStartAngle, endAngle: CircleEndAngle, clockwise: true) LoopCounter = LoopCounter + 1 CycleColorArrayIndex = CycleColorArrayIndex + 1 } for S in ShapeLayers { //TextNum.string = "\(S)" //view.layer.addSublayer(TextNum) view.layer.addSublayer(S) } } } }
Thanks for any suggestions/help
Matt P.