Creating a custom title bar on a standard NSWindow

时光毁灭记忆、已成空白 提交于 2019-12-02 19:43:13

I found one way to do it:

The trick is to keep the window style as the default and not set NSBorderlessWindowMask. Then you can add your custom title bar view to the window's theme frame like so:

NSView *themeFrame = [[window contentView] superview];
NSView *firstSubview = [[themeFrame subviews] objectAtIndex:0];
[titleBarView setAutoresizingMask:(NSViewMinYMargin | NSViewWidthSizable)];
[themeFrame addSubview:titleBarView positioned:NSWindowBelow relativeTo:firstSubview];

This basically just puts your custom title bar view on top of the standard title bar. You'll probably have to do some rejiggering to the view frames and window buttons. See INAppStoreWindow for some code examples of this.

The INAppStoreWindow project says that this method doesn't use any private APIs, and thus is able to be used on the App Store.

If you require the window to be transparent, you can just set the following on the window:

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