3

I am trying to create Borderless window with windows style mask set to "NSBorderlessWindowMask". The window is subclassed and return "Yes" for canBecomeKeyWindow and canBecomeMainWindow. I have to get only minimize button in my view at top left corner. I am getting instance of minimise button object using "[NSWindow standardWindowButton:NSWindowMiniaturizeButton forStyleMask:NSBorderlessWindowMask]" and adding it as subview . The button is present in nsview. But is grayed out and is enabled and is not in Yellow also. Once I click it , it turns yellow. And on mouse hover "-" that appears in minimise button is not turning in. I tried [button setHighlighted:YES] which actually appears as clicked. I have added tracking area to get mouse hover.

_minButton = [NSWindow standardWindowButton:NSWindowMiniaturizeButton forStyleMask:NSBorderlessWindowMask];
[_minButton setFrameOrigin:NSMakePoint(_minButton.frame.origin.x + 7, _minButton.frame.origin.y)];
[_minButton setTarget:self.view.window];
[_minButton setAction:@selector(miniaturize:)];
[self.view addSubview:_minButton];
NSTrackingArea* trackingArea = [[NSTrackingArea alloc]
                                initWithRect:[_minButton bounds]
                                options:NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways
                                owner:self userInfo:nil];
[_minButton addTrackingArea:trackingArea];

- (void)mouseEntered:(NSEvent *)theEvent{
 [[_minButton cell]setHighlighted:YES];
}

- (void)mouseExited:(NSEvent *)theEvent{
[[_minButton cell]setHighlighted:NO];
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
sac
  • 890
  • 6
  • 19
  • 1
    Show your full code — guessing what it's doing likely won't help. – l'L'l Jun 19 '14 at 05:25
  • possible duplicate of [Cocoa/OSX - NSWindow standardWindowButton behaving strangely once copied and added again](http://stackoverflow.com/questions/7634788/cocoa-osx-nswindow-standardwindowbutton-behaving-strangely-once-copied-and-add) – Valentin Shergin May 23 '15 at 20:46

2 Answers2

0

try calling

[_minButton setNeedsDisplay:YES];

at the end of the method

iwcoder
  • 144
  • 6
0

This worked for me. It's a hack, but it worked.

- (void)windowDidBecomeKey:(NSNotification *)notification {

[_minButton highlight:YES];
[_minButton highlight:NO];
James Bellamy
  • 361
  • 1
  • 3
  • 6