ios - Gradient color in Circle -


this question has answer here:

i have create circle animation, have created , working fine. problem add gradient color. please refer screen shot attached

circle gradient color

below code creating circle animation:

      let linewidth: cgfloat = 20        dispatch_async(dispatch_get_main_queue()) { () -> void in          let startangle = -90.0         let endangle = -90.01          let circlepath = uibezierpath(arccenter: cgpoint(x: self.frame.width/2,y: self.frame.height/2), radius: cgfloat(self.frame.width/2 - (self.linewidth/2)), startangle: cgfloat(((startangle) / 180.0 * m_pi)), endangle:cgfloat(((endangle) / 180.0 * m_pi)), clockwise: true)          // circle layer         let circlelayer = cashapelayer()         circlelayer.path = circlepath.cgpath         circlelayer.fillcolor = uicolor.clearcolor().cgcolor         circlelayer.strokecolor = uicolor.greencolor().cgcolor         circlelayer.strokeend = 94/100         circlelayer.linewidth = self.linewidth         circlelayer.zposition = 1          // background circle layer         let circlebackgroundlayer = cashapelayer()         circlebackgroundlayer.path = circlepath.cgpath         circlebackgroundlayer.fillcolor = uicolor.clearcolor().cgcolor         circlebackgroundlayer.strokecolor = uicolor.lightgraycolor().cgcolor         circlebackgroundlayer.strokeend = 1.0         circlebackgroundlayer.linewidth = self.linewidth         circlebackgroundlayer.zposition = -1          self.layer.addsublayer(circlelayer)         self.layer.addsublayer(circlebackgroundlayer)          // add animation         let pathanimation = cabasicanimation(keypath: "strokeend")         pathanimation.duration = 0.55         pathanimation.timingfunction = camediatimingfunction(name: kcamediatimingfunctionlinear)         pathanimation.fromvalue = 0         pathanimation.tovalue = 94/100          circlelayer.addanimation(pathanimation, forkey: "strokeend")      } 

my question in above code should add cagradientlayer add gradient color.

the below lines of code add gradient color:

       let gradient: cagradientlayer = cagradientlayer()         gradient.frame = cgrectmake(0, 0, 170, 170)         gradient.colors = [uicolor(hexstring: "#27c68a")().cgcolor, uicolor(hexstring: "#86ea26")().cgcolor]         gradient.cornerradius = gradient.frame.width/2         gradient.startpoint = cgpoint(x: 0,y: 1)         gradient.endpoint = cgpoint(x: 1, y: 0)         self.layer.insertsublayer(gradient, atindex: 0) 

if want real simulation of gradient color can check this answer .it's based on cross divided rectangular view in 4 portions, shift colors on each portion obtain regular gradient applied layer mask.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -