NSButton角半径和NSPopover

cma*_*hat 5 macos rounded-corners nsstatusitem nsbutton

我正在使用NSPopover,我将NSViewController放在内部,以显示为来自NSStatusItem的自定义视图.除了具有角半径的NSButton之外,大多数视图控制器都能正确显示.在应用圆角的地方有一些额外的白色泄漏.显示实际应用程序中的按钮,不会发生此问题.

我觉得必须对我设置为"NSAppearanceNameAqua"的NSPopover外观做些什么.

NSButton位于NSView中,显示在NSTableView中并设置为此样式.

    self.createdButton.wantsLayer = true
    self.createdButton.layer?.backgroundColor = Utils.blackColor().CGColor
    self.createdButton.layer?.masksToBounds = true
    self.createdButton.layer?.cornerRadius = 5
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述 在此输入图像描述

顶部图片是实际应用程序打开时的图像.底部图像是在NSPopover中显示视图控制器的时候.

his*_*boy 0

使用贝塞尔路径创建角半径,即

    NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:view.bounds xRadius:3 yRadius:3];
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.frame = view.bounds;
    maskLayer.path = path.toCGPath;
    self.containerView.layer.mask = maskLayer;
Run Code Online (Sandbox Code Playgroud)