johnson
johnson

Reputation: 167

Why isnt anything showing up?

I am creating a mutli color circle border using arcs, but I am not seeing anything in the view. I am using this question as reference. To check the arc class look at the link I provided. If the number at indexPath.item is greater than .69, I need an arc from 0 to .69 in red and the rest orange. By rest I mean the percentage in the array. What am I doing wrong?

if (number[indexPath.item] >= 0.70 ){

        let arc = Arc()

         let circlePath = UIBezierPath(arcCenter: CGPointMake(cell.progress.frame.width / 2, cell.progress.frame.height / 2), radius: CGFloat(60), startAngle: CGFloat(-M_PI_2), endAngle:CGFloat(M_PI * 2 * numbers[indexPath.item] - M_PI_2), clockwise: true)

        arc.addFigure(circlePath.CGPath, fillColor: UIColor.clearColor(), strokeColor: UIColor.redColor(), strokeStart: 0.0, strokeEnd: CGFloat(0.69), lineWidth: 5.0, miterLimit: 0.0, lineDashPhase: 0.0, layer: cell.progress.layer)

        arc.addFigure(circlePath.CGPath, fillColor: UIColor.clearColor(), strokeColor: UIColor.orangeColor(), strokeStart: CGFloat(0.69), strokeEnd: CGFloat(numbers[indexPath.item]), lineWidth: 5.0, miterLimit: 0.0, lineDashPhase: 0.0, layer: cell.progress.layer)

        let shapeLayer = CAShapeLayer()
        shapeLayer.path = circlePath.CGPath



        //shapeLayer.fillColor = UIColor.clearColor().CGColor

        //shapeLayer.strokeColor = UIColor.redColor().CGColor

        //shapeLayer.lineWidth = 5.0

        //cell.progress.layer.addSublayer(shapeLayer)
    }

Upvotes: 2

Views: 51

Answers (1)

Rob
Rob

Reputation: 437552

There are a bunch of issues here:

  1. For strokeStart and strokeEnd, you appear to doing radian angle calculations for a circular bezier curve, but that's not how addFigure is using these parameters. It's handing these off to the eponymous CAShapeLayer properties, and those go from 0 to 1, not 0 to M_PI * 2.0.

  2. The addFigure is creating a CAShapeLayer, but you're not doing anything with the return value. I would have thought that you'd add the resulting CAShapeLayer as sublayer or something like that.

Upvotes: 1

Related Questions