I want to "dock" a rectangular bar immediately below the menu bar. It was quite easy to use -NSMakeRect() with the appropriate screen width from [[NSScreen mainScreen] frame] and then I set my window style via:
[window setStyleMask:NSBorderlessWindowMask];
which works fine. I try to possition my window as high as possible via:
[window setFrameOrigin:NSMakePoint(0.0f, screenrect.size.height];
which almost works. What I see is that there is a gap between my window and the system menu bar that is exactly the height of the title bar of my window if it was displayed. I cannot push my window any higher.
Is it possible to position a borderless window immediately below the menu?
Related
I created a demo app in Delphi 11.1 and when I maximize the window, the title bar width gets re-sized (squeezed). Is this the windows' default behavior? How do I prevent it? I just wanted to keep the same title bar width even after the window is maximized.
Window not maximized:
Window maximized and title bar width is automatically reduced!!
My Mac app uses a floating window without a title bar that can be moved by dragging.
NSRect frame = NSMakeRect(500, 950, 600, 100);
self.lbWindow = [[lbCustomWindow alloc] initWithContentRect:frame
styleMask:NSWindowStyleMaskBorderless
backing:NSBackingStoreBuffered
defer:NO];
[self.lbWindow setOpaque:NO];
[self.lbWindow setBackgroundColor:[NSColor clearColor]];
[self.lbWindow setHasShadow:YES];
[self.lbWindow setReleasedWhenClosed:FALSE];
However, this window can't be placed (eg created at that position), or moved (by dragging) to just under the top menu bar, it can only get to about 30px below it - it's exactly the height of a normal window title bar - basically, the window seems to be vertically constrained as if the window had a title bar.
(The Y co-ord "950" is the highest I can place the window, which results in the image below.)
I'd like this to act as though there was no title bar, and be able to place it so the top edge of the window is just below the menu bar.
(I haven't included the custom window implementation, but there's not much in there apart from dragging support - and it's not the dragging that's causing the constraint, as is still applies when you just initially position the window programatically.)
Thoughts?
Ok, just after posting I've found out why (typical). :)
The (transparent) window is created ok, but when I add the subview to it, for some reason (refactored old code) it's being added a title bar's height lower than the top of the window.
(It's obvious when you make the window non-transparent).
So just need to reposition the view and I should be fine.
I have stumbled upon this window style:
HUD-style black, translucent window body, no visual difference between the title bar and the window content, red closing button. Is this window style officially offered by the system? If so, what do I do to get it?
I was able to get quite close with the following code:
[window setTitlebarAppearsTransparent:YES];
[[window standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
[[window standardWindowButton:NSWindowZoomButton] setHidden:YES];
Plus NSVisualEffectView for the blurred background.
I have created a custom title bar view for a blackened NSWindow (style 0), so that I can have it disappear in a similar manner to Quicktime X. The only problem is, the buttons don't respond to mouse over and mouse move actions on the title bar can get combined with pressing in the buttons.
The full source code is here: https://github.com/iaefai/OrganicUI under Classes/ORTitleBar.m and ORWindow.m.
The buttons are standard from this method:
self.closeButton = [NSWindow standardWindowButton: NSWindowCloseButton
forStyleMask:NSTexturedBackgroundWindowMask];
Then positioned:
[self.closeButton setFrame: __frame];
Then added to the titlebar:
[self addSubview: self.closeButton];
A small video of the disappearing title bar can be seen here:
http://web.me.com/iaefai/OrganicUI/ORWindow.html
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?
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