Reputation: 5344
I have created a custom window to override NSWindow. It works perfectly except for the fact that it has a shadow. I use [self setHasShadow:NO] to programatically set the shadow but it still remains. However if I check with [self hasShadow], it returns false.
The only way I seem to get the shadow to go away is if I turn shadow off in Interface Builder. Yeah, I realize this is okay, but I am curious about why the programatic setting doesn't override the Interface Builder setting even though other programatic settings do.
I am not allowed to post any code therefore please do not ask me to do so.
Do I need to do anything in addition to [self setHasShadow:NO] to set the shadow of the window programatically?
EDIT: Calling [self setHasShadow:NO]
from awakeFromNib
makes the shadow go away. However I want to remove the shadow directly from the constructor not awakeFromNib
Mac OSX Snow Leopard, Xcode 3.2.6
Upvotes: 1
Views: 1598
Reputation: 10198
This can be done if You call it in "awakeFromNib" or make borderless window like so:
- (id)initWithContentRect:(NSRect)contentRect
styleMask:(NSUInteger)windowStyle
backing:(NSBackingStoreType)bufferingType
defer:(BOOL)flag
{
self = [super initWithContentRect: contentRect
styleMask: NSBorderlessWindowMask
backing: NSBackingStoreBuffered
defer: NO];
if(self)
{
[self setHasShadow:NO];
[self setBackgroundColor:[NSColor clearColor]];
[self setOpaque:NO];
}
return self;
}
** I don't know if You have titlebar. If You have You should use styleMask: NSTitledWindowMask if not NSBorderlessWindowMask
But If You don't want to create borderless window also it should work when You call from "awakeFromNib":
-(void)awakeFromNib {
[self setHasShadow:NO];
}
I hope You choose for Your window class Your own writted class?? You can do this here:
Also You should write this to disable shadow if You use borderless window:
-(BOOL)hasShadow {
return NO;
}
Upvotes: 3