开发者

Borderless window and shadow in cocoa

I created a borderless window and i want to remove its shadow.

This is my init window code :

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

    if (![super initWithContentRect: contentRect
     开发者_JAVA技巧                     styleMask: NSBorderlessWindowMask 
                            backing: NSBackingStoreBuffered
                              defer: NO]) return nil;

    [self setHasShadow:NO];
    [self setOpaque:NO];
    [self setBackgroundColor:[NSColor clearColor]];
    [self setAcceptsMouseMovedEvents:YES];
    return self;
}

As you can see i use setHasShadow:NO but nothing happen and shadow still shows.

How can i remove shadow ?


Well, for one thing you should be assigning the result of your call to super to self:

self = [super initWithContentRect: contentRect
                      styleMask: NSBorderlessWindowMask 
                        backing: NSBackingStoreBuffered
                          defer: NO];
if(self)
{
    //continue with initialisation
}
return self;

Also , if the window is being loaded from a nib it may have a shadow specified in Interface Builder. Since the settings in the nib are loaded after the init method is called, they may override the settings in your init method.

The solution then is to either make sure that the window does not have the Shadow appearance checkbox selected in Interface Builder, or call [self setHasShadow:NO] in ‑awakeFromNib rather than in the initialiser.

‑awakeFromNib is always called after the nib file has been loaded and all outlets are connected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜