I create a NSWindow with transparent title using:
setTitleVisibility:NSWindowTitleHidden
setTitlebarAppearsTransparent:YES
setMovable:NO
and the style includes NSWindowStyleMaskFullSizeContentView. The window becomes title-less, zoom and fullscreen modes work well. Everything is ok, except the mouse cursor. It becomes the default one when I move it to the area where titlebar would be located if it was visible.
Is it possible to override this behavior so that the mouse cursor shape will be defined by the window content (which uses addCursorRect)?
There's a difference between a transparent titlebar and no titlebar at all. It sounds like you have a window with a transparent titlebar, but you want a window with no titlebar.
If you want no titlebar at all, you need to make sure the window's styleMask does not have NSWindowStyleMaskTitled.
If you create the window in a xib or storyboard, you can turn off the “Title Bar” checkbox in the window's Attributes inspector.
If you create the window in code, you can set the styleMask using the initWithContentRect:styleMask:backing:defer: initializer, or you can set the styleMask after creation.
For example, this line will remove the NSWindowStyleMaskTitled bit from an existing window's styleMask:
self.window.styleMask &= ~NSWindowSytleMaskTitled;
Related
How do I show resize indicators for an NSWindow without Titlebar?
I created a new Xcode project(for Mac app) with storyboard. I just disabled the checkbox Title Bar in Appearance(It hides the Title bar of NSwindow).
The strange thing was, after disabling the TitleBar, NSWindow was not showing resize indicators while mouse was above the window edges. Although if I drag at edges it was resizing.
I guess this is a bug, because if the window can be resized by dragging the mouse over edges, it must show the resize indicators.
As it can be seen in the image, the resize indicators are seen after user drags the window, but many users would think that since there is no resize indicator, the window is not resizable.
I've fixed this issue by subclassing NSWindow and overriding canBecomeKeyWindow to return YES:
#import "MyWindow.h"
#implementation MyWindow
- (BOOL)canBecomeKeyWindow {
return YES;
}
#end
Not updating resize cursors in this case looks like Apple bug. Documentation states "The value of canBecomeKeyWindow property is YES if the window has a title bar or a resize bar, or NO otherwise.", so I expect that canBecomeKeyWindow will return YES for resizable window. But it doesn't.
UPD: Checked on 10.10.5. Hopefully, you will have same behaviour on 10.11.
I have not checked this, but you could set the resize indicators manually. I think I would add four NSTrackingAreas to the windows contentView subclass (one for each side of the window, only few pixels in height/width).
In the mouseEntered() method, create a new NSCursor object for the appropriate mouse position. Remember that the position could change, so use the mouseMoved() method as well.
On mouseExited() reset the cursor.
Again, I have not tried this, but it should work.
PS: Don't forget to file a radar on this ;)
I have a semi-transparent NSView subclass that acts as a kind of tooltip. When the tooltip is drawn on the screen it draws on top of a form and so it covers a couple of NSTextField's.
When I hover the mouse over the tooltip at the spots where a NSTextField exists, the cursor changes to the input style cursor.
How can I prevent the cursor from changing?
Overlapping views are not really supported very well in Cocoa and the behaviour is undefined.
Instead, your tooltip view should be in its own borderless window, large enough to contain your view. The tooltip window should be a child window of the main window it's attached to. To make a window a child of another window, you use the addChildWindow:ordered: method of NSWindow.
Child windows are attached to the parent window and will move with their parent window when the parent window moves. If you just open a new window without making it a child window, it will be "left behind" if the other window is moved.
To make a borderless window, pass NSBorderlessWindowMask as the styleMask to the initWithContentRect:styleMask:backing:defer: method of NSWindow.
I am using standard HUD window (Drag and drop from IB Library). But I don't see any control to set the transparency of this HUD window.
I also tried to customize NSPanel to create HUD window . But whatever the alpha value I set. It takes default alpha value. One more problem in this approach is I think I need to draw tittle bar.
Any solution or alternate solution is appreciated.
This page has an example that subclasses NSPanel and draws an HUD Window completely from scratch. The background color/alpha can easily be changed from HUDWindow.m.
How can I write an own resize corner/handle for an NSWindow? I'm using a subclass of an NSWindow without the default resize corner, but I need it for my window.
The basic outline:
Create a view.
Put some "drag me" indicator appropriate to your window in the view.
Have the view's drag action method respond by resizing the window so that the corner in question is now located at the current mouse position.
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