Title Bar Buttons and Custom Title Bars - cocoa

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

Related

Floating window without titlebar won't go to the top of the screen

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.

Remove the baseline border of NSWindow title bar

Is there a way to remove the baseline border of the NSWindow title bar without subclass
the window and implement a title bar view myself? (traffic lights button is real tricky)
I wanted to make view and put it just under the window's title bar without the baseline
border so that the my view below will appear to be "stick" or "continued" from the
title bar, that is, if I made my view the same color as the title bar.
You can achieve that by:
window?.toolbar?.showsBaselineSeparator = false

Navigation bar turns solid black during push to new view controller

I have a UITableViewController embedded in a UINavigationController. Tapping a button pushes another view controller which has the navigation bar hidden. The issue is while the animation occurs, the navigation bar for the previous view turns a solid black.
Here's the best shot I could get. (The navigation bar is white by default)
http://imgur.com/fxU7VrS
Fixed by using
[self.navigationController setNavigationBarHidden:YES animated:YES];
instead of
self.navigationController.navigationBar.hidden = YES;

Selectable area for NSButton

So I am basically trying to make a list of selectable text items (just a list of text, no button bezels, backgrounds, etc.). I suppose that I could make this happen with an NSTableview, but trying to make the table view completely transparent and still functional was giving me some issues. Anwyays, I am trying to do it with NSButtons that I create programatically and add to my view in a list, without any background or bezel. However, when I set the properties to make the button transparent and without bezel, the clickable area of the button is relegated to the text of the title of the button alone. Clicking anywhere else that the button should be (around the title) no longer works. Here is the code I am using. I want to be able to click anywhere in the rect in which I create the button in order to cause a click. FYI I have tried NSSwitchButton without the checkbox image and it is the same thing. Thanks for your help!
for(NSString *theTask in theTasks){
NSButton *theCheckBox = [[[NSButton alloc] initWithFrame:NSMakeRect(xCoordinate + 25, yCoordinate + ([tasksWindow frame].size.height/2) - 60, [tasksWindow frame].size.width - 40, 25)] autorelease];
[theCheckBox setButtonType:NSToggleButton];
[theCheckBox setAction:#selector(taskChecked:)];
[[theCheckBox cell] setBackgroundColor:[NSColor clearColor]];
[[theCheckBox cell] setBordered:NO];
NSAttributedString *theTitle = [[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:#"%#", theTask] attributes:[NSDictionary dictionaryWithObject:[NSColor whiteColor] forKey:NSForegroundColorAttributeName]] autorelease];
[theCheckBox setAttributedTitle:theTitle];
[[tasksWindow contentView] addSubview:theCheckBox];
yCoordinate -= 20;
}
UPDATE: I've been able to confirm that setting the background color to clear is what seems to cause the button to stop responding to clicks within its full boundaries (not the removal of the border).
So to answer my own question, it was because I was overlaying the transparent buttons atop a transparent NSWindow (which refuses mouse events). I simply had to set the window NOT to ignore mouse events and the behavior went away.

Changing color of the NSWindow titlebar

I am developing a desktop application in which I want to change the color of the title bar of an NSWindow. How exactly can I do this?
NSWindow's content view has a superview, which is an instance of NSThemeFrame. That class is responsible for drawing the title text, the window/toolbar background texture, and it contains subviews for everything else (close button, full screen button, NSDocument icon, etc).
You can use the Objective-C runtime to replace NSThemeFrame's drawRect: method with your own method, which will call the parent implementation and then perform custom drawing on top of it.
There is also a private method to find the rect the title is drawn in, and public methods on NSFont to find it's font and font size.
What I did is set the window background colour to be a solid colour (black) instead of a gradient/texture, then set it to be a "textured" window (which causes the background colour to actually be rendered, otherwise it would not happen), then I draw a black square over the title bar in the area where I know the title has already been drawn, then draw my own title in it's place, with light grey instead of dark grey.
Source code is here: https://github.com/abhibeckert/Dux/blob/master/Dux/DuxProjectWindow.m (note: it only does a custom title text colour if DUX_DARK_MODE == 1)
Doing this will probably get your app blocked from the Mac App Store, but it is fairly reliable. Just make sure you test it with every new major version of OS X.
To change the color of the window's toolbar:
Set window style Textured in Attribute inspector.
In code: [window setBackgroundColor: MyCustomColor];
This uses private methods, but works:
NSEnumerator *viewEnum = [[[[[[window contentView] superview] titlebarViewController] view] subviews] objectEnumerator];
NSView *viewObject;
while(viewObject = (NSView *)[viewEnum nextObject]) {
if([viewObject className] == #"NSTextField") [viewObject setTextColor: .. your color .. ];
}

Resources