gpt4 book ai didi

macos - NSButton 圆角半径和 NSPopover

转载 作者:行者123 更新时间:2023-12-03 17:41:01 29 4
gpt4 key购买 nike

我正在使用 NSPopover 并且我将一个 NSViewController 放入其中以显示为来自 NSStatusItem 的自定义 View 。大多数 View Controller 显示正确,除了 NSButton 上有圆角半径。在应用圆角的地方有一些额外的白色泄漏。在实际应用程序中显示按钮,不会发生此问题。

我觉得它必须与我设置为“NSAppearanceNameAqua”的 NSPopover 外观有关。

NSButton 位于 NSView 中,NSView 显示在 NSTableView 中并设置为这种样式。

    self.createdButton.wantsLayer = true
self.createdButton.layer?.backgroundColor = Utils.blackColor().CGColor
self.createdButton.layer?.masksToBounds = true
self.createdButton.layer?.cornerRadius = 5

enter image description here
enter image description here

顶部图像是实际应用程序打开时的图像。
底部图像是在 NSPopover 中显示 View Controller 时的图像。

最佳答案

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

    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;

关于macos - NSButton 圆角半径和 NSPopover,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36169817/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com