2014-04-17 1 views
1

저는 UIBezierPath를 처음 시도하고 있으며, 색상으로 그렸지만 성공하지 못한 그래프를 채우려고합니다. 그냥 [barGraph fill]를 추가베 지어 패스로 그려진 그래프 색상을 채우려 고 시도했습니다.

- (void)calculateGraphSize 
{ 
    self.topY = CGRectGetMinY(self.bounds); 
    self.bottomY = CGRectGetMaxY(self.bounds); 
    self.minX = CGRectGetMinX(self.bounds); 
    self.maxX = CGRectGetMaxX(self.bounds); 
} 

- (void) drawRect: (CGRect) rect 
{ 
    CGSize cornerRadius = CGSizeMake(10.0f, 10.0f); 

    [self calculateGraphSize]; 

    UIBezierPath *graphBorder = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:cornerRadius]; 
    [[UIColor redColor] setFill]; 
    [graphBorder fill]; 


    UIBezierPath *barGraph = [UIBezierPath bezierPath]; 
    barGraph.lineWidth = 2.0f; 

    CGPoint point = CGPointMake(self.minX, self.bottomY); 
    [barGraph moveToPoint:point]; 

    point = CGPointMake(self.minX + 50, self.bottomY - 50); 
    [barGraph addLineToPoint:point]; 

    point = CGPointMake(self.minX + 100, self.bottomY - 75); 
    [barGraph addLineToPoint:point]; 

    point = CGPointMake(self.minX + 200, self.bottomY); 
    [barGraph addLineToPoint:point]; 

    [[UIColor blackColor] setStroke]; 
    [[UIColor greenColor] setFill]; 
    [barGraph closePath]; 
    [barGraph stroke]; 
} 

답변

0

:

[[UIColor blackColor] setStroke]; 
[[UIColor greenColor] setFill]; 
[barGraph closePath]; 
[barGraph fill]; 
[barGraph stroke]; 

당신은 아마 입력하고 채우기 은폐 할 경우 다음 스트로크 내가 기억할 수 없기 때문에 원하는 이것은 내가 정의의 UIView 내에서 한 일이다 뇌졸중 (나는 항상 하를 확인해야한다!)

+0

Doh는 그 커피를 필요로한다 – Gruntcakes

+0

항상 길 - 당신이 무엇을 놓쳤는 지 안다. :) – Rich

+0

또 다른 가능성은 한 번의 호출로 채우기 및 획을 수행 할 수있는 CGContextDrawPath를 사용하는 것입니다. –