2014-02-18 1 views
0

나는 draw rect에서 다음 코드를 사용하여 간단한 채워진 원을 그립니다.다른 원과 함께 CGContextFillEllipseInRect를 사용하여 만든 원을 자르는 방법

CGContextRef con = UIGraphicsGetCurrentContext(); 
CGContextAddEllipseInRect(con, CGRectMake(0,0,self.bounds.size.width,self.bounds.size.height)); 
CGContextSetFillColorWithColor(con, [UIColor blueColor].CGColor); 
CGContextFillPath(con); 

제대로 원을 그립니다. 이제 중간에 다른 작은 원이있는 원을 잘라서 원이되고 원 아래에있는 것이 무엇이든 볼 수 있습니다. 내가 어떻게 할 수 있니?

답변

0

은 내가 EO 규칙을 사용하여 그렇게 할 수 있었다.

CGContextRef con = UIGraphicsGetCurrentContext(); 
CGContextAddEllipseInRect(con, rect); 
CGContextAddEllipseInRect(con, CGRectInset(rect, 40, 40)); 
CGContextSetFillColorWithColor(con, [UIColor blueColor].CGColor); 
CGContextEOFillPath(con); 
+0

내가 말했듯이 대답은 엉망이 아닙니다. – peko

0

사용 CGContextEOClip와 짝수 홀수 규칙()

CGSize size = rect.size; 
CGContextRef context = UIGraphicsGetCurrentContext(); 

CGContextTranslateCTM(context, 0, 0); 
CGContextSaveGState(context); 

CGContextAddPath(context, ([UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, size.width, size.height)].CGPath)); 
CGContextAddPath(context, ([UIBezierPath bezierPathWithOvalInRect:CGRectMake(size.width/4, size.height/4, size.width/2, size.height/2)].CGPath)); 
CGContextEOClip(context); //clip 
CGContextAddPath(context, [UIBezierPath bezierPathWithRect:rect].CGPath); 

CGContextSetFillColorWithColor(context, [UIColor greenColor].CGColor); 
CGContextFillPath(context); 

CGContextRestoreGState(context); 
관련 문제