分两步走:
1.子类化NSWindow,主要是重载了下面这个函数
- (id)initWithContentRect:(NSRect)contentRect
                styleMask:(NSUInteger)aStyle
                  backing:(NSBackingStoreType)bufferingType
                    defer:(BOOL)flag {
    self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
    if (self != nil) {
        [self setOpaque:NO];
        [self setBackgroundColor:[NSColor clearColor]];
    }
    return self;
}

2.子类化NSWindow的view,重载drawRect,其中的圆角半径和背景颜色自己可以调整
- (void)drawRect:(NSRect)dirtyRect
{
    [NSGraphicsContext saveGraphicsState];

    NSRect rect = [self bounds];
    NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:5 yRadius:5];
    [path addClip];
    
    [[NSColor controlColor] set];
    NSRectFill(dirtyRect);
    
    [NSGraphicsContext restoreGraphicsState];
    
    [super drawRect:dirtyRect];
}

实现demo效果如下:

NSWindow如何实现圆角

相关文章:

  • 2021-11-03
  • 2022-12-23
  • 2021-12-03
  • 2022-01-07
  • 2021-11-05
  • 2021-07-27
猜你喜欢
  • 2021-07-23
  • 2021-08-21
  • 2021-04-18
  • 2021-12-12
  • 2022-12-23
  • 2021-09-11
相关资源
相似解决方案