如何获得默认的darkmode“有色” Nswindow标题栏和内容视图背景的颜色?

发布于 2025-01-26 03:09:04 字数 1316 浏览 4 评论 0原文

设置:

Mac OS Monterey 12.3.1(21E258)

步骤

  1. 激活黑暗模式。
  2. 启动XCode。
  3. 文件>新>项目> Macos>应用,单击“下一步”。
  4. 产品名称:colortest,接口:XIB,语言:Objective-C
  5. 位置:DEKTOP,单击“创建”
  6. 产品>运行

结果

请参阅最高的应用程序窗口启动。窗口标题栏的颜色和窗口内容视图背景颜色都略微着色,以匹配当前选择的桌面背景。这些是纯色。它们是不是半透明的“材料”颜色。

可以通过启动“常规”系统偏好窗格来看到这些相同的有色颜色。

我想通过编程性

地获得这两种颜色(可靠但有色的title bar颜色和固体但有色的窗口内容背景颜色),这样我就可以在>的运行时绘制它们 - [nsview drawrect:]。我期望这样的事情:

NSColor *color = [NSColor windowBackgroundColor];
[color setFill];
NSRectFill(self.bounds);

我以为- [NScolor WindowbackgroundColor]可能会返回其中一种或另一种颜色,但事实并非如此。我已经检查了许多其他这样的标准颜色方法nscolor,但它们都不匹配这两种颜色。

在运行时发现这两种颜色似乎应该非常简单。但是我很难过。找不到它们。他们在哪里?

Setup:

Mac OS Monterey 12.3.1 (21E258)

Steps

  1. Activate Dark Mode.
  2. Launch Xcode.
  3. File > New > Project > macOS > App, click "Next".
  4. Product Name: ColorTest, Interface: Xib, Language: Objective-C
  5. Location: Dektop, click "Create"
  6. Product > Run

Result

See ColorTest app window launch. The window titlebar color and window content view background color are both slightly tinted to match the currently selected Desktop background. These are solid colors. They are not semi-transparent "material" colors.

enter image description here

These same tinted colors can be seen by launching the "General" System Preference pane.

enter image description here
enter image description here

Problem

I want to get these two colors (solid yet tinted titlebar color and solid but tinted window content background color) programmatically so I can paint them at runtime inside of -[NSView drawRect:]. I expect something like this:

NSColor *color = [NSColor windowBackgroundColor];
[color setFill];
NSRectFill(self.bounds);

I thought -[NSColor windowBackgroundColor] might return one or the other of these colors, but it does not. I have checked many other such standard color methods of NSColor, but none of them match these two colors.

It seems like it should be extremely simple to find these two colors at runtime. But I'm stumped. Can't find them. Where are they?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

悲欢浪云 2025-02-02 03:09:04

您需要nsvisualeffectView带有.behindwindow与.contentbackground和.titlebar材料混合模式。然后在DrawRect中使用这些颜色会导致您看到的内容。

You need NSVisualEffectView with .behindWindow blendingMode with .contentBackground and .titlebar materials. And then using those colors in drawRect will result in what you see.

翻身的咸鱼 2025-02-02 03:09:04

创建一个nsvisualeffectView,将混合模式设置为.withinwindow

    let effectView = NSVisualEffectView(frame: NSRect(x: 0, y: 0, width: 100, height: 100))
    effectView.blendingMode = .withinWindow
    effectView.material = .titlebar // or .windowBackground
    view.addSubview(effectView)

Create a NSVisualEffectView with blending mode set to .withinWindow.

    let effectView = NSVisualEffectView(frame: NSRect(x: 0, y: 0, width: 100, height: 100))
    effectView.blendingMode = .withinWindow
    effectView.material = .titlebar // or .windowBackground
    view.addSubview(effectView)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文