2014-02-14 4 views
1

이 질문에 대한 답을 쉽게 찾을 것으로 예상되었지만, 불행히도 검색 결과가 나오지 않았습니다. iOS에서 그런 서클을 그리는 방법은 무엇입니까?iOS에서 분할 원을 그리는 방법은 무엇입니까?

enter image description here

+3

는'CGPathAddArc는 (...)'(있는 CoreGraphics) 또는'addArcWithCenter 얼마나 멀리 않았다 반경 : startAngle로부터 : endAngle : 시계 방향 :'(UIBezierPath에)를 사용하면 얻을? –

+0

@ DavidRönnqvist 힌트를 보내 주셔서 감사합니다. 어디서부터 시작해야할지 모르겠다. –

+0

환영합니다. 같은 질문을 가진 사람들이 유익을 얻을 수 있도록 회신하여 자신의 질문에 대한 답변을 게시하십시오. –

답변

3

나는 UIBezierPath를 사용하여 끝났다. 나는 흰색 원 모양을 만들기 위해 중간에 흰색 원을 추가 루프 후 코드의 짧은 조각을 추가 할 수 있었다 안드레이의 답변을 사용

CGFloat DegreesToRadians(CGFloat degrees) 
{ 
    return degrees * M_PI/180; 
}; 

- (void)drawRect:(CGRect)rect 
{ 
CGFloat radius = 70; 
CGPoint center = CGPointMake(90 + radius, 170 + radius); 
CGFloat start = DegreesToRadians(-90), end; 

NSArray *angles = @[@"0", @"60", @"-90"]; 
NSArray *colors = @[[UIColor yellowColor], [UIColor blueColor], [UIColor redColor]]; 

int col_counter = 0; 

for (NSString *angle in angles) 
{ 
    CGFloat value = [angle floatValue]; 
    end = DegreesToRadians(value); 

    CGPoint next; 
    next.x = center.x + radius * cos(start); 
    next.y = center.y + radius * sin(start); 

    UIBezierPath *path = [UIBezierPath bezierPath]; 

    [path moveToPoint:center]; 
    [path addLineToPoint:next]; 
    [path addArcWithCenter:center radius:radius startAngle:start endAngle:end clockwise:YES]; 
    [path addLineToPoint:center]; 

    UIColor *color = colors[col_counter]; 
    [color set]; 
    [path fill]; 

    col_counter++; 

    start = end; 
} 
} 
1

이 내가 주어진 원을 그리는 방법이다 두꺼운, 멀티 컬러 국경.

enter image description here

end = DegreesToRadians(360); 

start = DegreesToRadians(-90); 

int width = 10; // thickness of the circumference 
radius -= width; 

CGPoint next; 
next.x = center.x + radius * cos(start); 
next.y = center.y + radius * sin(start); 

UIBezierPath *path = [UIBezierPath bezierPath]; 

[path moveToPoint:center]; 
[path addLineToPoint:next]; 
[path addArcWithCenter:center radius:radius startAngle:start endAngle:end clockwise:YES]; 
[path addLineToPoint:center]; 

UIColor *color = [UIColor whiteColor]; 
[color set]; 
[path fill]; 
관련 문제