Change border corlor of NSTableView

大憨熊 提交于 2019-12-24 03:15:00

问题


Can I change the color of NSTableView's border. The gray line at the pointer. Thanks.


回答1:


You need to SubClass your NSScrollView . NSScrollView doesn't usually do any drawing, and probably has a weird interaction with its child views in that way. I'd suggest putting something like

- (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];
}



回答2:


Easy way to set border to scrollview

let scrollView = NSScrollView()
scrollView.contentView.wantsLayer = true
scrollView.contentView.layer?.borderColor = NSColor.black
scrollView.contentView.layer?.cornerRadius = 6


来源:https://stackoverflow.com/questions/17045005/change-border-corlor-of-nstableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!