2017-03-07 1 views
1

원이 그려지는 원이 단색이면 충분합니다. 하지만 두 가지 색상이 필요합니다. 위치 0은 녹색이고 위치 360은 빨간색입니다. 위치 180은 절반 녹색의 절반 빨간색이어야합니다. 여기색상 그라디언트가있는 UIBeziepath

let center = CGPoint(x: bounds.midX, y: bounds.midY) 

     // Calculate the center difference between the end and start angle 
     let angleDiff: CGFloat = endAngle.toRads - startAngle.toRads 
     // Calculate how much we should draw depending on the value set 
     let arcLenPerValue = angleDiff/CGFloat(maxValue) 
     // The inner end angle some basic math is done 
     let innerEndAngle = arcLenPerValue * CGFloat(value) + startAngle.toRads 

     // The radius for style 1 is set below 
     // The radius for style 1 is a bit less than the outer, this way it looks like its inside the circle 
     var radiusIn = (max(bounds.width - outerRingWidth*2 - innerRingSpacing, bounds.height - outerRingWidth*2 - innerRingSpacing)/2) - innerRingWidth/2 

     // If the style is different, mae the radius equal to the outerRadius 
     if viewStyle >= 2 { 
      radiusIn = (max(bounds.width, bounds.height)/2) - (outerRingWidth/2) 
     } 


     // Start drawing 
     let innerPath = UIBezierPath(arcCenter: center, 
            radius: radiusIn, 
            startAngle: startAngle.toRads, 
            endAngle: innerEndAngle, 
            clockwise: true) 
     innerPath.lineWidth = innerRingWidth 
     innerPath.lineCapStyle = innerCapStyle 
     innerRingColor.setStroke() 
     innerPath.stroke() 

당신이 그라데이션을 적용하는 방법을 알아 내 원을 그리는 코드?

답변

0

경로는 일반적으로 단일 색상을 사용하여 그려집니다.

그라디언트를 사용하여 패스를 그리려면 CAShapeLayer를 만들고 패스를 설치 한 다음 해당 패스를 그라데이션 레이어의 마스크로 만들 수 있습니다.

코어 그래픽 및 블렌드 모드를 사용하여이 작업을 수행 할 수도 있습니다.

관련 문제