如何自定义拖放NSTableView的样式?

Coc*_*ser 3 cocoa

我对基于视图的NSTableview的拖放有一些疑问.

在此输入图像描述在此输入图像描述

  1. 如何更改拖放高亮颜色?
  2. 如何更改拖放矩形的形状(宽度和高度)?

提前致谢

Sim*_*n M 7

您应该能够在NSTableRowView子类中执行以下操作:

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

    [self setDraggingDestinationFeedbackStyle:NSTableViewDraggingDestinationFeedbackStyleNone];

    return self;
}

- (void)drawDraggingDestinationFeedbackInRect:(NSRect)dirtyRect {
    NSRect drawRect = [self bounds];
    // Tweaking the size of the drawing rectangle...
    aRowRect.size.height--;
    aRowRect.size.width-=2;
    aRowRect.origin.x++;

    NSBezierPath *backgroundPath = [NSBezierPath bezierPathWithRect:drawRect];
    [[NSColor redColor] set];
    [backgroundPath fill];
    [[NSColor greenColor] set];
    [backgroundPath stroke];
}
Run Code Online (Sandbox Code Playgroud)

当然,如果您没有构建以圣诞为主题的应用程序,您将需要更改这些颜色.