0

I have a HUD Panel which has couple buttons, a label, and a textfield where a user can input. Right now it works perfectly fine, except I want to get rid of the title bar. It is really easy to get rid of the title bar, as I can just uncheck the "Title Bar" in the interface builder. The problem is, when I get rid of the title bar, it becomes un-editable, so the user cannot type in anything in the textfield. Why is this, and how could I fix it?

I know I could write a custom window by myself programmatically, but I really just need to remove the title bar and I have everything else set up with the builder already, so I wanted to find a simple way to fix this problem, (hopefully) if there is any.

Thanks in advance.

Dennis
  • 3,506
  • 5
  • 34
  • 42

2 Answers2

1

You need to override canBecomeKeyWindow and return YES.

From the docs: The NSWindow implementation returns YES if the window has a title bar or a resize bar, or NO otherwise.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • I tried canBecomeKeyWindow and other things as well (as described in http://stackoverflow.com/questions/5013695/how-do-i-create-a-custom-borderless-nswindow-in-objective-c-cocoa), but it still does not work. Maybe it's because it's a panel instead of a window? – Dennis Apr 01 '12 at 07:00
  • @Dennis, That's not it. I made it work with a panel. I just subclassed NSPanel and added the one method:- (BOOL)canBecomeKeyWindow {return YES;} – rdelmar Apr 01 '12 at 15:06
  • Yeah.. I got confused about subclassing the panel and stuff but now I got it to work except I changed it to a window since it will be easier for me to set other things as well. Thanks anyway :) – Dennis Apr 01 '12 at 19:50
1

All You need to do is:

Subclass Your NSPanel and override canBecomeKeyWindow as rdelmar mentioned.

You can do it like this:

create panel class:

.h

@interface panel : NSPanel {

}

@end

.m

#import "panel.h"

@implementation panel

-(BOOL)canBecomeKeyWindow
{
    return YES;
}

@end

Don't forget to change panel's class to Your created class in identity inspector.

enter image description here

Justin Boo
  • 10,132
  • 8
  • 50
  • 71
  • Thanks for the answer but I just ended up creating a custom window programmatically since there were some other issues as well. Thank you though. – Dennis Apr 01 '12 at 09:12