更改NSTableView的边框

问题描述 投票:2回答:2

我可以改变NSTableView's border的颜色吗?指针处的灰线。谢谢。

macos cocoa nstableview
2个回答
7
投票

你需要SubClass你的NSScrollViewNSScrollView通常不做任何绘图,并且可能以这种方式与其子视图进行奇怪的交互。我建议做点什么

- (void)drawRect:(NSRect)dirtyRect {
    [super drawRect:dirtyRect];
    // We're going to be modifying the state for this, 
    // so allow it to be restored later
    [NSGraphicsContext saveGraphicsState];

    // Choose the correct color; isFirstResponder is a custom     
    // ivar set in becomeFirstResponder and resignFirstResponder
    [[NSColor redColor]set];

    // Create two rects, one slightly outset from the bounds,
    // one slightly inset
    NSRect bounds = [self bounds];
    NSRect innerRect = NSInsetRect(bounds, 2, 2);
    NSRect outerRect = NSMakeRect(bounds.origin.x - 2, 
                                  bounds.origin.y - 2,
                                  bounds.size.width + 4,
                                  bounds.size.height + 4);

    // Create a bezier path using those two rects; this will
    // become the clipping path of the context
    NSBezierPath * clipPath = [NSBezierPath bezierPathWithRect:outerRect];
    [clipPath appendBezierPath:[NSBezierPath bezierPathWithRect:innerRect]];

    // Change the current clipping path of the context to 
    // the enclosed area of clipPath; "enclosed" defined by 
    // winding rule. Drawing will be restricted to this area.
    // N.B. that the winding rule makes the order that the
    // rects were added to the path important.
    [clipPath setWindingRule:NSEvenOddWindingRule];
    [clipPath setClip];
    // Fill the rect; drawing is clipped and the inner rect
    // is not drawn in
    [[NSBezierPath bezierPathWithRect:outerRect] fill];
    [NSGraphicsContext restoreGraphicsState];
}

0
投票

将边框设置为scrollview的简便方法

let scrollView = NSScrollView()
scrollView.contentView.wantsLayer = true
scrollView.contentView.layer?.borderColor = NSColor.black
scrollView.contentView.layer?.cornerRadius = 6
© www.soinside.com 2019 - 2024. All rights reserved.