대답은 user1118321에서 왔지만 인라인으로 회신하기보다는 인라인 그림이 있도록이 답변을 게시하고 있습니다. 우선은 벤 다이어그램 색상의 더 나은 세트를 선택 :
이러한 색상이 중복 서로를 숨 깁니다. 이 솔루션은 kCGBlendModeScreen을 사용하는 것이었다 :
그러나이 원래 색상을 증강. 여기에, 호기심 또는 게으른 그 코드를
코드의 일부입니다 : 이에 대한 해결책은 검은 색으로 배경을 설정하는 것이 었습니다. touchesBegan/Ended/Moved 이벤트에서 SMVennObjects를 만들고 나서 drawRect에서 그립니다. SMVennObject는 단지 두 개의 CGPoint와 UIColor (정적 int를 사용하여 순차적으로 할당 됨)를 포함합니다.
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect{
for(NSUInteger index = 0; index < self.vennObjects.count; index++){
NSLog(@"drawing index %d", index);
SMVennObject* vo = [self.vennObjects objectAtIndex:index];
[self drawVennObject:vo context:UIGraphicsGetCurrentContext()];
}
}
-(void)drawVennObject:(SMVennObject*)vo context:(CGContextRef)cgContext{
if((vo.pointBegin.x == 0 && vo.pointBegin.y == 0) ||
(vo.pointEnd.x == 0 && vo.pointEnd.y == 0)){
return;
}
CGContextBeginPath(cgContext);
CGContextSetLineWidth(cgContext, 2.0f);
// Convert UIColor to raw values
CGFloat red = 0.0;
CGFloat green = 0.0;
CGFloat blue = 0.0;
CGFloat alpha = 0.0;
[vo.color getRed:&red green:&green blue:&blue alpha:&alpha];
alpha = 1.0;
CGFloat color[4] = {red, green, blue, alpha};
CGContextSetBlendMode(cgContext, kCGBlendModeScreen);
CGRect r = CGRectMake(MIN(vo.pointBegin.x, vo.pointEnd.x),
MIN(vo.pointBegin.y, vo.pointEnd.y),
fabs(vo.pointBegin.x - vo.pointEnd.x),
fabs(vo.pointBegin.y - vo.pointEnd.y));
// Draw ellipse
CGContextSetFillColor(cgContext, color);
CGContextFillEllipseInRect(cgContext, r);
// Draw outline of ellipse
CGContextSetStrokeColor(cgContext, color);
CGContextStrokeEllipseInRect(cgContext, r);
}
이것은 쉽게 타원 대신 직사각형을 사용하여 수행 할 수 있습니다. 사용자 측에서 무엇을 생각하겠습니까? 오히려 타원을 보시겠습니까? 비록 당신이 그들을 가다듬어도 직사각형을 사용하는 것처럼 곧바로 사용할 수는 없습니다. – VaporwareWolf