2009-12-28 3 views

답변

6

당신이없는 경우하지 마십시오 휠을 너무 많이 다시 발명. 스크롤 막대의 모양을 사용자 정의하려면 NSScroller를 서브 클래스 화하고 다양한 draw 메소드를 오버라이드하는 것이 더 쉬울 수도 있습니다.

이것은 테스트되지 않은 코드이지만 자신의 이미지가 MyKnob.png 인 경우 노브의 모양을 사용자 정의하기 위해 수행해야 할 작업을 보여 주어야합니다.


@interface MyScroller : NSScroller 
{ 
    NSImage *knobImage; 
} 
@end 




@implementation MyScroller 

- (void) dealloc 
{ 
    [knobImage release]; 
    [super dealloc]; 
} 

- (id) initWithFrame:(NSRect) frame 
{ 
    self = [super initWithFrame:frame]; 
    if (!self) return nil; 

    knobImage = [[NSImage imageNamed:@"MyKnob.png"] retain]; 

    return self; 
} 

- (void) drawKnob 
{ 
    // Work out where exactly to draw the knob 
    NSPoint p = NSMakePoint(0.0, 0.0); 

    [knobImage drawAtPoint:p fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0]; 
} 

@end 

+0

FWIW, 명명 된 이미지는 사라지지 않습니다. NSImage는 이들을 글로벌 풀에 보관합니다. 그래도 -retain은 아무런 상처를주지 않습니다. – NSResponder

0

좋은 시작은 Aaron Hillegass가이 기사를 살펴 보는 것입니다. link text

대릴