2012-08-17 2 views
2

나는 다음과 같은 NSSegmentedCell의 서브 클래스를 생성 drawWithFrame을 구현 한 드로잉 : 난에 마우스로 클릭하는 경우에만 세그먼트가 응용 프로그램의 처음 실행에 그려진되지 않은됩니다NSSegmentedCell 서브 클래스가

#import "CustomSegmentedCell.h" 

@implementation CustomSegmentedCell 

- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { 

    int i=0, count=[self segmentCount]; 
    NSRect segmentFrame=cellFrame; 

    for(i=0; i<count; i++) { 
     segmentFrame.size.width=[self widthForSegment:i]; 
     [NSGraphicsContext saveGraphicsState]; 
     // Make sure that segment drawing is not allowed to spill out into other segments 
     NSBezierPath* clipPath = [NSBezierPath bezierPathWithRect: segmentFrame]; 
     [clipPath addClip]; 
     [self drawSegment:i inFrame:segmentFrame withView:controlView]; 
     [NSGraphicsContext restoreGraphicsState]; 
     segmentFrame.origin.x+=segmentFrame.size.width; 
    } 

    _lastDrawRect=cellFrame; 

} 

@end 

문제를, 그것은 볼 얻는다 빈 영역 어디 세그먼트 화 된 컨트롤을 그려 가정합니다. 제발 알려주지, 여기에 무엇이 누락되었습니다.

감사합니다,

답변

2

서브 클래스와 코드를 drawSegment:inFrame:withView:

- (void)drawSegment:(NSInteger)segment inFrame:(NSRect)frame withView:(NSView *)controlView 
{ 
    NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:frame xRadius:8 yRadius:8]; 
    [path setClip]; 
    [path setLineWidth:2.5]; 
    [[NSColor grayColor] setStroke]; 
    NSColor* bgColr; 
    if (segment%2) { 
     bgColr = [NSColor blackColor]; 
    } 
    else { 
     bgColr = [NSColor redColor]; 
    } 

    [bgColr setFill]; 
    [NSBezierPath fillRect:frame]; 

} 
+0

감사합니다 Parag 구현은, 요구 사항은 아주 나이,하지만 난 당신의 도움을 주셔서 감사합니다. – AmitSri

관련 문제