How to change the height of the NSWindow header?

I want to change the height of the NSWindow header.

Here are some examples: alt text

BUT...

alt text

I could use NSToolbar, but the problem is that I cannot place the height of the views (for example: I cannot place the segmentedControl higher than in the picture because there is still a header) alt text

If I remove the title, I cannot place the NSToolbar, and the window will not move.

Do you have any ideas?

+8
cocoa macos nswindow
source share
4 answers

INAppStoreWindow is a subclass of NSWindow, it will tell you how to change the height of the title bar.

https://github.com/indragiek/INAppStoreWindow

http://iloveco.de/adding-a-titlebar-accessory-view-to-a-window/
This example shows how to add buttons in the title bar.

+4
source share

This is much simpler than you might think. I also went looking for something similar for my application.

Real App Store app: Here is the App Store app ...

The App App App is similar: My App Store look-alike ...

There is no disrespect for INAppStoreWindow, it is a very good implementation and strong. The only rollback I saw from it was that there was a lot of drawing code along with the tightly tuned TitleBar color settings that Apple can set at any time.

So here is how I did it:

A) Create a standard window with the title, Close, Minimize, Shadow, Resize, Full Screen - The primary window. Note. You do not need a textured window and you do not have to specify a title

B) Then add a standard toolbar with these settings:

  • Icon only
  • Visible at startup - ON
  • Customizable - OFF
  • Separator - ON
  • Size - Regular

Remove all toolbar items and add them only in the following order

NSSegmentControl (51 x 24) - | Flexible space | - NSSearchField (150 x 25)

C) In your Content View, directly below the toolbar, add a regular sized NSButton, for example:

  • Bordered - OFF
  • Transparent - OFF
  • Title -
  • Image -
  • Position - text below the button
  • Font - Small 11 System

Ok, pretty easy so far, right ?!

In your window manager or app delegation .... set IBOutlet (s) to NSButton (s)

Note. Remember to enable IBOutlet in the interface builder.

Well, don't be afraid, we need to write a tiny bit of code:

In awakeFromNib or windowDidLoad ....

  • Get a view of content supervisors (also known as NSThemeView)
  • Remove your button from the supervisor
  • Set the frame of your button
  • Add button back to theme view

Thus, the code will look something like this:

NSView *themeView = [self.contentView superview]; NSUInteger adj = 6; [self.btnFeatured removeFromSuperview]; self.btnFeatured.frame = NSMakeRect( self.btnFeatured.frame.origin.x, self.window.frame.size.height - self.btnFeatured.frame.size.height - adj, self.btnFeatured.frame.size.width, self.btnFeatured.frame.size.height); [themeView addSubview:self.btnFeatured]; 

What is it! You can use your outlet to turn on / off your button, adjust the mask image when it is selected, turn on / off the toolbar, or even hide everything and add a window title. All this without problems if Apple changes the standard window title windows.

PS There were no private frameworks in this publication!

+23
source share

You need to subclass NSWindow and execute your own window drawing frame. This is not just about the headline. This is about the entire window frame (so you can actually put the close / minimize / zoom buttons at the bottom if you want).

A good starter is on Cocoa With Love .

+4
source share

There are several new solutions based on INAppStoreWindow and without warnings and log messages for those who want to change the height of NStitlebar, change the position of the traffic light, add an element (e.g. NSbutton) to NStitlebar and change it please check below.

WAYWindow: https://github.com/weAreYeah/WAYWindow

NStitlebar_with_item: https://github.com/ZHANGneuro/NStitlebar_with_item

+1
source share

Source: https://habr.com/ru/post/650853/


All Articles