我想改变它的颜色,但我不确定是否继承了NSScrollView或NSClipView。或者如果角落可以作为常规NSView插入。
我不需要代码。只是暗示如何做到这一点。
答案 0 :(得分:1)
mekentosj已经answered elsewhere on stackoverflow了。子类的类是NSScrollView。
@interface MyScrollView : NSScrollView {
}
@end
@implementation MyScrollView
- (void)drawRect:(NSRect)rect{
[super drawRect: rect];
if([self hasVerticalScroller] && [self hasHorizontalScroller]){
NSRect vframe = [[self verticalScroller]frame];
NSRect hframe = [[self horizontalScroller]frame];
NSRect corner;
corner.origin.x = NSMaxX(hframe);
corner.origin.y = NSMinY(hframe);
corner.size.width = NSWidth(vframe);
corner.size.height = NSHeight(hframe);
// your custom drawing in the corner rect here
[[NSColor redColor] set];
NSRectFill(corner);
}
}
@end
答案 1 :(得分:0)
有点奇怪,但只是继承NSScrollView并使用super.drawRect()覆盖绘制使得我的NSScrollView(不是)用白色填充那个角落。我测试了它2倍以确保,因为它没有多大意义。
import Cocoa
class ThemedScrollView: NSScrollView {
override func drawRect(dirtyRect: NSRect) {
super.drawRect(dirtyRect)
if hasVerticalScroller && hasHorizontalScroller {
guard verticalScroller != nil && horizontalScroller != nil else { return }
let vFrame = verticalScroller!.frame
let hFrame = horizontalScroller!.frame
let square = NSRect(origin: CGPoint(x: hFrame.maxX, y: vFrame.maxY), size: CGSize(width: vFrame.width, height: hFrame.height))
let path = NSBezierPath(rect: square)
let fillColor = NSColor.redColor()
fillColor.set()
path.fill()
}
}
}
以下是原始答案的Swift变体:
http.get('http://www.google.com/', function(response) {