2009-12-28 130 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

达里尔