2013-12-18 3 views
3

UIBezierPath를 사용하여 작성한 원형 진행률 표시 줄에서 작업하고 있습니다. 진행 표시 줄은 다음 그림과 같습니다UIBezierPath로 작성한 호에 둥근 모서리를 적용하십시오.

enter image description here

내 질문은 : 어떻게 둥근 원호의 가장자리를 확인하고 직사각형하지? 처럼

난 호를 그리는 데 사용되는 코드는 같습니다

// Draw the arc with bezier path 
     int radius = 100; 

     arc = [CAShapeLayer layer]; 
     arc.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(100, 50) radius:radius startAngle:M_PI endAngle:M_PI/150 clockwise:YES].CGPath; 
     arc.position = CGPointMake(CGRectGetMidX(self.view.frame)-radius, 
            CGRectGetMidY(self.view.frame)-radius); 
     arc.fillColor = [UIColor clearColor].CGColor; 
     arc.strokeColor = [UIColor purpleColor].CGColor; 
     arc.cornerRadius = 0.5; 
     arc.lineWidth = 6; 

     [self.view.layer addSublayer:arc]; 

     // Animation of the progress bar 
     drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; 
     drawAnimation.duration   = 5.0; // "animate over 10 seconds or so.." 
     drawAnimation.repeatCount   = 1.0; // Animate only once.. 
     drawAnimation.removedOnCompletion = YES; // Remain stroked after the animation.. 
     drawAnimation.fromValue = [NSNumber numberWithFloat:0.0f]; 
     drawAnimation.toValue = [NSNumber numberWithFloat:10.0f]; 
     drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; 
     [arc addAnimation:drawAnimation forKey:@"drawCircleAnimation"]; 

내가 arc.cornerRadius을 사용하려고하지만 아무것도 돌려주지 않는 것 같았다.

도움을 주시면 감사하겠습니다.

미리 감사드립니다.

화강암 lineCapStylekCGLineCapRound 행 (베 지어 경로)

답변

13

세트는 둥근 가장자리 라인의 끝을 그리는.

도형 레이어에 lineCap을 설정하여 동일한 작업을 수행 할 수도 있습니다.

+0

고마워요. 작동 중입니다. – Granit

+0

@Grangji 예에서 여전히 작동하지 않습니다. 내가 뭘 잘못하고 있니? –

+2

UIBezierPath가 아닌 CAShapeLayer에 설정해야합니다. –

7

모서리를 둥글게하려면 이걸 사용하면됩니다.

arc.lineCap = @"round"; 
+0

적절한 상수를 사용하십시오! 'kCGLineCapRound' – Warpling

+0

@Warpling kCGLineCapRound를 사용해 보았지만 작동하지 않았습니다. "둥근"효과가있었습니다. kCGLineCapRound가 작동하지 않는 이유는 무엇입니까? –

+0

@RajTandel 확실하지 않습니다. 'lineCap'을 설정하지 않고'lineCapStyle'을 설정하지 않겠습니까? – Warpling

관련 문제