2009-12-28 96 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將它們保存在全局池中。儘管如此,保留並沒有傷害任何東西。 – NSResponder 2009-12-29 06:02:51

0

一個好的開始是看看Aaron Hillegass的這篇文章。 link text

達里爾