更改NSTableView的边框corlor [英] Change border corlor of NSTableView

查看:547
本文介绍了更改NSTableView的边框corlor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以更改 NSTableView的边框的颜色。指针处的灰线。
谢谢。

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

推荐答案

您需要将 NSScrollView 子类化。 NSScrollView 通常不会做任何绘图,并可能有一个奇怪的交互与其子视图的方式。我建议把像

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

这篇关于更改NSTableView的边框corlor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆