当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - Grey border around view when using NSBorderlessWindowMask

问题描述:

I'm having the exact same problem as in this question:

Gray border when using NSBorderlessWindowMask

However, the accepted answer (as in the comments) of removing the window shadow doesn't seem to work, at least on Lion.


I've subclassed NSWindow, and created a borderless window in this manner:

-(id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag {

self = [super initWithContentRect:contentRect

styleMask:(NSBorderlessWindowMask | NSResizableWindowMask)

backing:bufferingType

defer:flag];

[self setMovableByWindowBackground:YES];

[self setOpaque:NO];

[self setBackgroundColor:[NSColor clearColor]];

[self setHasShadow:YES];

[self setLevel:NSMainMenuWindowLevel];

return self;

}

Please note that this app will only be run on Lion (so NSResizableWindowMask doesn't change the appearance). I tried disabling the shadow, and toggling numerous settings for my window but I can't seem to remove this grey border:

Nowhere in my code do I add a border. I simply have a NSSplitView added in Interface Builder in a window. During runtime I add the colored view as a subview to the left pane of the split view, completely filling the bounds of the left split view.

Edit: This happens even using a simple NSView, not even a split view.


TL;DR: Why does my NSView have a grey border around it?

网友答案:

ok got it. to remove the shadow simply add this to your NSWindow subclass:

- (BOOL)hasShadow {
    return NO;
}

and to remove the border you need to know that this border is coming from the view - not the window (just like you said it in your edit). So you have to disable the border for the view with this code:

[myview setBorderType:NSNoBorder];
分享给朋友:
您可能感兴趣的文章:
随机阅读: