创建完全自定义的NSAlert [英] Creating a fully customized NSAlert

查看:1545
本文介绍了创建完全自定义的NSAlert的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以创建完全自定义的提醒?我现在正在使用自定义工作表,但我想要的工作表阻止的功能(如 - [NSAlert runModal] )。

Is it possible to create a fully customized alert? I'm doing it with custom sheets now, but I'd like to have the feature that the sheet is blocking (like -[NSAlert runModal]).

我只是想改变背景,真的,和文本的颜色,当然。

I just want to change the background, really, and the text color, of course.

推荐答案

关于推荐解决方案的警告

此代码会导致浪费和无意义的开销:

This code causes wasteful and pointless overhead:

for (;;) {
    if ([NSApp runModalSession:session] != NSRunContinuesResponse)
        break;
}

此代码直接从Apple文档页面复制,开发人员其中可以插入有意义的代码以用于后台执行。也就是说,你应该在break和结束括号之间有一些代码。但是没有实例中显示的实际代码 - 并且运行它只是使应用程序反复轮询会话,直到它结束。就像两岁的孩子在车后座问道:我们还在吗?我们还在吗?我们还在吗?

This code is copied straight from the Apple documentation page - but it's meant to show the developer where meaningful code can be inserted for background execution while the modal runs. That is, you should have some code between the break and the closing bracket. But there's no actual code shown in the example - and running it like this simply causes your application to poll the session repeatedly until it ends. It's like the two-year-old in the back seat of the car on a road trip asking, "Are we there yet? Are we there yet? Are we there yet?..."

如果你只是想直接模态执行,你的应用程序提供一个模态窗口,并暂停主/背景窗口的处理,直到模态结束,使用这个:

If you just want straightforward modal execution, where your application presents a modal window and suspends processing of main / background windows until the modal ends, use this:

[NSApp runModalForWindow: self.window];

...然后当窗口关闭时退出模态会话,将其放入您的窗口控制器子类:

...and then exit the modal session when the window closes by dropping this into your window controller subclass:

- (void)windowWillClose:(NSNotification *)notification {
    [NSApp stopModal];
}

这篇关于创建完全自定义的NSAlert的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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