NSWindow with custom shadow

这一生的挚爱 提交于 2019-12-01 11:47:43

问题


I want to draw a custom shadow on an NSWindow-Object.

Is there a way to do this by passing an own NSShadow-Object to NSWindow? Or a (private) method, where I can put my own drawing code?

Thanks,


回答1:


Don't. You shouldn't alter the look of the window. Changing the look of UI is only allowed for Apple. Normal apps should use the standard one.

That said, there's a way, if you really insist on doing that. You can't just attach an NSShadow, unfortunately. Also, as far as I understand, there's no private method which draw the shadow. That's done by the Window Server, not by the app.

But you can ask the window server not to add the shadow. Have you noticed that in the Interface Builder, there's an option suppressing the shadow of a given window? That corresponds to the property hasShadow of an NSWindow.

After suppressing the shadow, you just need to draw everything by yourself. A nice sample code that does the custom window drawing is available at ADC, so have a look at it.



来源:https://stackoverflow.com/questions/4861784/nswindow-with-custom-shadow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!