当窗口有焦点时更改NSView背景颜色 [英] Change NSView background color when window has focus

查看:253
本文介绍了当窗口有焦点时更改NSView背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,当应用程序窗口包含一个大纲视图(如XCode),它会改变颜色时,该窗口的焦点。以XCode为例,如果窗口是当前的,那么大纲视图有一个蓝色的背景,如果它失去焦点,它变灰,

I have noticed when an apps window contains an Outline view (such as XCode) it changes color when that window is in focus. With XCode for example, if the window is current then the outline view has a blueish background, if it looses focus it goes grey,

任何人都可以帮我复制这个?我假定它与 drawRect:有关,但是只能设法在窗口加载时改变颜色。

Can anyone help me to replicate this? I presume its something to do with drawRect: but can only manage to get the color to change when the window loads.

也许它是一个内置函数,我只是缺少一些东西?

Maybe its a built in function and I'm just missing something?

推荐答案

c $ c> -drawRect:是检查窗口是否具有状态,并相应地绘制:

All you have to do in your -drawRect: is check whether the window has main status and draw accordingly:

- (void)drawRect:(NSRect)rect
{
    if ([[self window] isMainWindow]) {
        // draw active appearance
    } else {
        // draw inactive appearance
    }
}

这篇关于当窗口有焦点时更改NSView背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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