如何隐藏NSDocument的窗口标题栏中的文件图标 [英] How to hide file icon in window titlebar of NSDocument

查看:195
本文介绍了如何隐藏NSDocument的窗口标题栏中的文件图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道如何隐藏基于文档的应用程序窗口的标题栏中的小图标?

Does anyone know how to hide the little icon in the titlebar of a document based app window?

NSWindow的文档说:

The docs for NSWindow say:


要自定义文档图标,可以使用以下代码段:

To customize the document icon, you can use the following code segment:



[[window standardWindowButton:NSWindowDocumentIconButton] setImage:nil];

但这不工作,因为窗口:stardardWindowButton:NSWindowDocumentIconButton返回nil,根据文档意味着该按钮不在窗口的视图层次结构中。

But that doesn't work because window:stardardWindowButton:NSWindowDocumentIconButton returns nil, which, according to the docs means that the button is not in the window's view hierarchy.

我已经看过NSDocument,但是这似乎并没有引用任何地方的图标。

I've looked around NSDocument, but that doesn't seem to refer to the icon anywhere.

我也试过了如何显示没有图标的文档窗口的标题?,但它们不工作。

I've also tried all the answers in How to show a title of document window without icon?, but they don't work. I'm guessing something has changed in Mavericks.

推荐答案

事实证明,标题栏中的文件图标是一个NSThemeDocumentButton按钮。奇怪的是,它不存在的时间windowControllerDidLoadNib被调用,但它确实存在以后。所以我把一点点延迟我的代码和bam,有它。

It turns out that the file icon in the title bar is a NSThemeDocumentButton button. Oddly, it doesn't exist by the time windowControllerDidLoadNib is called, but it does exist "later". So I put a little delay in my code and bam, there it is.

这是我在windowControllerDidLoadNib中输入的:

This is what I put in windowControllerDidLoadNib:

dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC));
dispatch_after(delayTime, dispatch_get_main_queue(), ^(void){
    NSWindow *window = self.windowForSheet;
    [[window standardWindowButton:NSWindowDocumentIconButton] setImage:nil];
});

这篇关于如何隐藏NSDocument的窗口标题栏中的文件图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆