使用NSBorderlessWindowMask时,视图周围有灰色边框 [英] Grey border around view when using NSBorderlessWindowMask
问题描述
我遇到的问题与这个问题完全相同:
I'm having the exact same problem as in this question:
使用NSBorderlessWindowMask时的灰色边框
但是,删除窗口阴影的接受答案至少在狮子会上。
However, the accepted answer (as in the comments) of removing the window shadow doesn't seem to work, at least on Lion.
我已经将 code>,并以这种方式创建了一个无边框窗口:
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;
}
请注意,此应用程式只会在Lion上执行$ c> NSResizableWindowMask 不会改变外观)。我尝试禁用阴影,并为我的窗口切换许多设置,但我似乎无法删除此灰色边框:
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:
我的代码中没有任何地方可以添加边框。我只需在窗口中的Interface Builder中添加一个 NSSplitView
。在运行时,我将彩色视图作为子视图添加到拆分视图的左窗格,完全填充左拆分视图的边界。
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.
编辑:即使使用简单的 NSView
,甚至不能拆分视图。
This happens even using a simple NSView
, not even a split view.
TL; DR
:为什么我的 NSView
周围有灰色边框?
TL;DR
: Why does my NSView
have a grey border around it?
推荐答案
确定了。删除阴影只需将它添加到您的 NSWindow
子类:
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];
这篇关于使用NSBorderlessWindowMask时,视图周围有灰色边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!