[英]Custom Mac Scrollbars With Cocoa
如何使用cocoa创建自定义滚动条?
如果你不需要,不要重新发明过多的轮子。 如果您只想自定义滚动条的外观,则可能更容易继承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
梦幻般的BWToolkit http://www.brandonwalkin.com/bwtoolkit/有自己独特的Scroll View实现。 源代码会告诉你它是如何完成的。
一个好的开始是看看Aaron Hillegass的这篇文章。 链接文字
达里尔
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.