【问题标题】:NSButton corner radius and NSPopoverNSButton 圆角半径和 NSPopover
【发布时间】:2016-07-10 06:01:15
【问题描述】:

我正在使用 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

顶部图像是实际应用打开时的图像。 下图是视图控制器在 NSPopover 中显示时的图像。

【问题讨论】:

  • 当您说“顶部图像是实际应用程序打开时”与“视图控制器正在 NSPopover 中显示”时,您是什么意思?所以应用程序没有在底部图像中打开?
  • 我正在创建一个显示在顶部菜单栏中的 NSStatusItem。当您单击菜单栏中的图标时,会出现一个 NSPopover,其中包含这些按钮的视图控制器。
  • 我发现的一件事是,如果您以编程方式在 contentViewController 中添加按钮,然后将它们四舍五入,它们将正确地四舍五入。但是,在 Xib/Storyboard 中从 Interface Builder 链接相同的按钮/视图将不会应用正确的舍入,至少这是我所经历的。可能是 AppKit 中的错误?
  • 你解决过这个问题吗?

标签: macos rounded-corners nsbutton nsstatusitem


【解决方案1】:

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

    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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-28
    • 2021-12-27
    • 2015-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-29
    相关资源
    最近更新 更多