NSWindow with round corners and shadow

后端 未结 11 1871
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-23 02:26

I\'m trying to crate a NSWindow without title bar (NSBorderlessWindowMask) with round corners and a shadow, similar to the below \"Welcome

11条回答
  •  不知归路
    2020-12-23 02:50

    try this:

    - (id)initWithContentRect:(NSRect)contentRect
                    styleMask:(NSUInteger)windowStyle   
                      backing:(NSBackingStoreType)bufferingType
                        defer:(BOOL)deferCreation
    {
        self = [super
                initWithContentRect:contentRect
                styleMask:NSBorderlessWindowMask | NSResizableWindowMask
                backing:bufferingType
                defer:deferCreation];
        if (self)
        {
            [self setOpaque:NO];
           [self setBackgroundColor:[NSColor clearColor]];            
    
        }
    
          [self setHasShadow:YES];
    
    
        [self setMovableByWindowBackground:YES];
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(didBecomeKey:) name:NSWindowDidBecomeKeyNotification object:self];
    
        return self;
    }
    
    -(void)didBecomeKey:(NSNotification *)notify{
        [self performSelector:@selector(invalidateShadow) withObject:nil afterDelay:.1];
    }
    

提交回复
热议问题