Change color of title bar in cocoa

不问归期 提交于 2019-12-19 04:42:46

问题


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?


回答1:


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.




回答2:


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.




回答3:


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];




回答4:


If you don't mind private API, you could subclass NSThemeFrame.




回答5:


Setting title bar appears as transparent

self.window.titlebarAppearsTransparent = YES;

And setting window background color as you wish



来源:https://stackoverflow.com/questions/2798605/change-color-of-title-bar-in-cocoa

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