在 Mac OS X 的桌面上绘图 [英] Drawing on desktop in Mac OS X
问题描述
我想创建程序 conky 的模拟.在 OS X 桌面上绘制信息的最佳方式是什么?
I want to create analog of program conky. What is the best way to draw information on a OS X desktop?
推荐答案
NSWindow 有一个方法,setLevel:
,它可以让你控制窗口相对于其他窗口的定位方式.根据我自己的经验,您可能想尝试输入 kCGDesktopIconWindowLevel
,并调用 setHasShadow:NO
来实现您想要的外观.要实际进行绘图,您需要在窗口中放置一个自定义 NSView 子类,并创建没有框架(参见 NSBorderlessWindowMask
)和透明([window setBackgroundColor:[NSColor clearColor]])的窗口,[self setOpaque:NO];
).
NSWindow has a method, setLevel:
, that lets you control how the window is positioned compared to other windows. From my own experience, you might want to try feeding it kCGDesktopIconWindowLevel
, and calling setHasShadow:NO
to implement the look you want. To actually do the drawing you would put a custom NSView subclass in your window, and create the window without a frame (see NSBorderlessWindowMask
) and transparent ([window setBackgroundColor:[NSColor clearColor]], [self setOpaque:NO];
).
您可能还想看看看看这篇文章 以固定您的窗口在 Expose 事件期间到桌面.
You might also want to take a look at this article to keep your window pinned to the desktop during an Expose event.
这篇关于在 Mac OS X 的桌面上绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!