本文介绍了如何在Objective-C中自定义绘制窗口标题栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自定义我在OS X上绘制窗口标题栏的方式。具体来说,我想做一些类似于Twitterrific应用程序,其中有一个自定义关闭按钮,没有最小/最大化按钮,窗口标题文本是右对齐的。不像Twitterrific,我不想定制绘制整个窗口(虽然我也不完全反对)。

I'd like to customize the way I draw the window title bar on OS X. Specifically, I'd like to do something like the Twitterrific app where there is a custom close button, no min/max buttons, and the window title text is right-justified. Unlike Twitterrific, I'm not looking to custom draw the entire window (though I'm not completely opposed to that either).

我已经看到了RoundWindow示例在可爱与爱以及Apple提供的RoundTransparentWindow示例,但似乎都不合适。

I've already seen the RoundWindow sample on Cocoa With Love as well as the RoundTransparentWindow example Apple provides, but neither seems appropriate.

推荐答案

如果你不想使用无边框窗口类,那么你可以做几件事。

If you don't want to use a borderless window class then you can do a couple of things.

首先,你可以使用自定义close / min / [NSWindow standardWindowButton:] 。一旦你得到的按钮,你可以定位/删除它/ etc ...

First, you can customize the close/min/max buttons buy using -[NSWindow standardWindowButton:]. Once you get the button you can position it/remove it/etc...

你可以通过设置标题为 @自定义标题, 。然后你可以添加一个 NSTextField 来绘制你自己的标题通过执行以下 [[[NSWindow contentView] superview] addSubview:textField]

You can customize the title by setting the title to @"". Then you can add a NSTextField to draw your own title by doing the following [[[NSWindow contentView] superview] addSubview:textField].

这可能是最简单的方法。

This is probably the easiest way to do things.

另一种方法是自定义绘制所有窗口标题栏的视图等。

Another way to do this is to customize the view that draws all the window title bar, etc...

NSWindow的内容视图位于主题视图中。你可以继承主题视图,并做你自己的图纸。唯一的问题是主题视图是一个私人类,所以你必须要小心。

NSWindow's content view's is inside a "theme view". You can subclass the theme view and do your own drawing. The only problem is that the theme view is a private class so you'll have to be careful.

这篇关于如何在Objective-C中自定义绘制窗口标题栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 05:26