2016-08-30 1 views
0

코어 그래픽을 사용하여 두 개의 직사각형 모양의 경로를 만들려고합니다. 색상을 사용하여 패스를 채우려고하면 겹쳐진 색상이 채워지지 않습니다.CoreGraphics - 색상이 채워지지 않은 겹치는 경로 영역

는 출력

enter image description here

내가 녹색 컬러 모두 폐쇄 구역을 채워 져야 할

- (void)drawRect:(CGRect)rect { 

    CGPoint topLeft = CGPointMake(121, 116); 
    CGPoint topRight = CGPointMake(221, 216); 

    CGPoint middleLeft = CGPointMake(121, 180); 
    CGPoint middleRight = CGPointMake(221, 280); 

    CGPoint bottomLeft = CGPointMake(250, 56); 
    CGPoint bottomRight = CGPointMake(350, 156); 

    CGMutablePathRef subpath1 = CGPathCreateMutable(); 
    CGPathMoveToPoint(subpath1, NULL, topLeft.x, topLeft.y); 
    CGPathAddLineToPoint(subpath1, NULL, topRight.x, topRight.y); 
    CGPathAddLineToPoint(subpath1, NULL, middleRight.x, middleRight.y); 
    CGPathAddLineToPoint(subpath1, NULL, middleLeft.x, middleLeft.y); 
    CGPathAddLineToPoint(subpath1, NULL, topLeft.x, topLeft.y); 
    CGPathCloseSubpath(subpath1); 

    CGMutablePathRef subpath2 = CGPathCreateMutable(); 
    CGPathMoveToPoint(subpath2, NULL, middleLeft.x, middleLeft.y); 
    CGPathAddLineToPoint(subpath2, NULL, middleRight.x, middleRight.y); 
    CGPathAddLineToPoint(subpath2, NULL, bottomRight.x, bottomRight.y); 
    CGPathAddLineToPoint(subpath2, NULL, bottomLeft.x, bottomLeft.y); 
    CGPathAddLineToPoint(subpath2, NULL, middleLeft.x, middleLeft.y); 
    CGPathCloseSubpath(subpath2); 

    CGMutablePathRef path = CGPathCreateMutable(); 
    CGPathAddPath(path, NULL, subpath1); 
    CGPathAddPath(path, NULL, subpath2); 
    CGPathCloseSubpath(path); 


    CGContextRef context = UIGraphicsGetCurrentContext(); 

    CGContextSetFillColorWithColor(context, [UIColor colorWithRed:0.19 green:0.42 blue:0.09 alpha:1.0].CGColor); 
    CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:0.19 green:0.42 blue:0.09 alpha:1.0].CGColor); 
    CGContextSetBlendMode(context, kCGBlendModeMultiply); 
    CGContextSetAlpha(context, 1.0); 

    CGContextAddPath(context, path); 
    CGContextDrawPath(context, kCGPathFillStroke); 
} 

이다 사용되는 코드이다. 어떤 방법으로이 문제를 해결할 수 있습니까?

답변

1

전체 경로를 채우기/채우기는 채우기 규칙으로 인해 경로 내에 빈 공간이 생기기 때문에 발생합니다. 대신 배경 경로 채우기/획을 그려야합니다. 그런 다음 전경 경로 채우기/획을 그립니다. 예를 들어 :

CGContextAddPath(context, subpath1); 
CGContextDrawPath(context, kCGPathFillStroke); 

CGContextAddPath(context, subpath2); 
CGContextDrawPath(context, kCGPathFillStroke); 

또한 내 의견으로는 사용하기 좋네요으로 UIBezierPath를 사용하는 것이 좋습니다.

관련 문제