如何获得默认的darkmode“有色” Nswindow标题栏和内容视图背景的颜色?
设置:
Mac OS Monterey 12.3.1(21E258)
步骤
- 激活黑暗模式。
- 启动XCode。
- 文件>新>项目> Macos>应用,单击“下一步”。
- 产品名称:colortest,接口:XIB,语言:Objective-C
- 位置:DEKTOP,单击“创建”
- 产品>运行
结果
请参阅最高的应用程序窗口启动。窗口标题栏的颜色和窗口内容视图背景颜色都略微着色,以匹配当前选择的桌面背景。这些是纯色。它们是不是半透明的“材料”颜色。
可以通过启动“常规”系统偏好窗格来看到这些相同的有色颜色。
我想通过编程性
地获得这两种颜色(可靠但有色的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
- Activate Dark Mode.
- Launch Xcode.
- File > New > Project > macOS > App, click "Next".
- Product Name: ColorTest, Interface: Xib, Language: Objective-C
- Location: Dektop, click "Create"
- 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.
These same tinted colors can be seen by launching the "General" System Preference pane.
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要
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.创建一个
nsvisualeffectView
,将混合模式设置为.withinwindow
。Create a
NSVisualEffectView
with blending mode set to.withinWindow
.