2014-05-11 2 views
0

NSTableview의 뷰 기반 셀에 배경색이있는 원을 그리려하고 있습니다. 나는 많은 옵션을 시도했는데 아무 문제가 없었다.코코아에서 동그라미를 그리는 법

drawRect 메소드에서 NSView 서브 클래스와 클리핑 된 원형 패스를 사용했습니다. 그것은 효과가 있었지만, 테이블 뷰를 스크롤 할 때마다 모양이 더 이상 원형이 아니 었습니다.

CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort]; 
NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:dirtyRect xRadius:10.0 yRadius:5.0]; 
[path addClip]; 
// Fill in background Color 
const CGFloat *components = CGColorGetComponents(backgroundColor.CGColor); 
CGContextSetRGBFillColor(context, components[0],components[1],components[2],components[3]); 
CGContextFillRect(context, NSRectToCGRect(dirtyRect)); 
[super drawRect:dirtyRect]; 

또한 경 사진 단추 (반올림 됨)를 사용해 보았지만 배경색을 셀에 설정하면 둥글 못했습니다. 그것은 사각형이되었습니다.

[result.tagImageButton.cell setBackgroundColor:[NSColor redColor]]; 

답변

2

사용 [self bounds] 대신 dirtyRect. 스크롤보기가 스크롤 될 때 셀에 자체의 일부만 그리도록 요청할 수 있습니다. 이 경우 dirtyRect은 셀보다 작습니다. 이 경우 전체 셀을 계속 그리는 것이 좋습니다.