更改可可中标题栏的颜色
这个问题肯定有人问过,但谷歌搜索后我仍然找不到答案。
如何将标题栏(可以使用关闭、最小化和最大化按钮单击并拖动的标题栏)的颜色更改为与 Cocoa 中默认灰色不同的颜色?
This must have been asked before, but after Googling I still can't find the answer.
How do you change the color of the title bar (The bar that you can click and drag around with the close, minimize and maximize buttons) to a different color than the default gray in Cocoa?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您设置“纹理”窗口的背景颜色(这种区别在 Snow Leopard 中并不明显),该颜色也将应用于标题栏。这就是火狐浏览器所做的。
我建议虽然没有真正的标题栏(即将您的窗口设置为没有标题栏)并使用
+[NSWindow standardWindowButton:forStyleMask:]
并将您自己的按钮放在“标题栏”中。这使您可以更好地控制并且不那么麻烦。If you set the background color of a "textured" window (a distinction that isn't really all that visible in Snow Leopard) that color will be applied to the titlebar as well. This is what Firefox does.
I would recommend though not having a real titlebar (i.e. setting your window to have no titlebar) and using
+[NSWindow standardWindowButton:forStyleMask:]
and putting your own buttons in the "titlebar". This allows you more control and is way way less hacky.如果它是一个面板,您可以通过将其实例化为 HUD 窗口。
否则,你不能。有没有注意到其他应用程序中没有任何带有不同颜色标题栏的 Aqua 窗口?这就是原因。
更改标题栏外观的唯一其他方法(不依赖于私有实现细节,例如框架视图的存在)是使窗口无边框并从头开始创建其标题栏和窗口按钮。
If it's a panel, you can change it to black by instantiating it as a HUD window.
Otherwise, you can't. Ever notice how there aren't any Aqua windows with different-colored title bars roaming around in other apps? This is why.
The only other way to change the appearance of the title bar (without relying on private implementation details such as the existence of a frame view) is to make the window borderless and create its title bar and window buttons from the ground up.
如果您采用 Colin 在界面生成器中制作窗口纹理的方法(窗口属性中的复选框),则可以在 appDelegate.m 文件的此函数中更改窗口背景颜色的行
/ /在这个函数中--->
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
//输入这个
[_window setBackgroundColor: NSColor.whiteColor];
If you go with Colin's approach of making the window textured in interface builder (check box in the attributes of the window), here's the line to change the background color of the window you'd put in this function of the appDelegate.m file
//In this function --->
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
//type this
[_window setBackgroundColor: NSColor.whiteColor];
设置标题栏显示为透明
self.window.titlebarAppearsTransparent = YES;
并根据需要设置窗口背景颜色
Setting title bar appears as transparent
self.window.titlebarAppearsTransparent = YES;
And setting window background color as you wish
如果你不介意私有 API,你可以继承 NSThemeFrame。
If you don't mind private API, you could subclass NSThemeFrame.