ios - Swift draw several paths in loops -


i'm working on changing circlechart, donutchart (that can support more 1 number).

i got angle's correct, changed data work array.

but when try draw paths, draws last one.

here's example screenshot of issue:

enter image description here

in above example, it's set draw array:

cell.circlechart.percentfills = [weight, 10] 

where weight % shown in label of circle. can see, doesn't draw first angle, starting point next angle correct.

here's code draw donut chart.

    override func drawrect(rect: cgrect) {     // define center.     let center = cgpoint(x:bounds.width/2, y: bounds.height/2)      // define radius     let radius: cgfloat = max(bounds.width, bounds.height)      // define starting , ending angles     var startangle: cgfloat = cgfloat(degreestoradians(-90))     let endangle: cgfloat = cgfloat(degreestoradians(270))      // set full path. (for default background color)     var path = uibezierpath(arccenter: center,         radius: bounds.width/2 - arcwidth/2,         startangle: startangle,         endangle: endangle,         clockwise: true)      // draw full chart background color     path.linewidth = arcwidth     chartcolor.setstroke()     path.stroke()      //calculate arc each per percent     let arclengthperpercent = cgfloat(degreestoradians(360/100))      // temporary var loop testing     var = 0      println("startangle before loop: \(radianstodegrees(double(startangle)))")      percentfill in percentfills {          println("loop: \(i)")          if == 0 {             fillcolor = uicolor.formulabluecolor()             println("blue")         } else {             fillcolor = uicolor.formulagreencolor()             println("green")         }          //then multiply out actual percent         let fillendangle = arclengthperpercent * cgfloat(percentfill) + startangle          println("fillendangle: \(radianstodegrees(double(fillendangle)))")          //2 - draw outer arc         var fillpath = uibezierpath(arccenter: center,             radius: bounds.width/2 - arcwidth/2,             startangle: startangle,             endangle: fillendangle,             clockwise: true)          progressline.path = fillpath.cgpath         progressline.strokecolor = fillcolor.cgcolor         progressline.fillcolor = uicolor.clearcolor().cgcolor         progressline.linewidth = arcwidth          // add curve screen         self.layer.addsublayer(progressline)          i++         startangle = startangle+(arclengthperpercent * cgfloat(percentfill))     }  } 

i reckon i'm going wrong in last bit, add progressline sublayer, don't know else should doing here instead.

of course i've tested if have 1 value in array, draws intended (in blue color)

any getting several paths drawn out, appreciated!

but when try draw paths, draws last one.

the problem progressline declared outside routine. therefore adding same path layer on , on sublayer - not multiple path sublayers. therefore appears once in interface, containing path (segment) recently assigned — last 1 in last iteration of loop.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -