开发者

Change color of title bar in cocoa

开发者 https://www.devze.com 2022-12-29 13:04 出处:网络
This must have been asked before, but after Goog开发者_运维百科ling I still can\'t find the answer.

This must have been asked before, but after Goog开发者_运维百科ling 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?


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.


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.


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


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


Setting title bar appears as transparent

self.window.titlebarAppearsTransparent = YES;

And setting window background color as you wish

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号