Hello to all,
If I create an NSTextField in the controller view, everything will be fine - the field is editable. Unfortunately, I need to create an NSTextField in a new custom NSWindow. My code below gives a field that looks without focus (text selection is gray) and cannot be edited (no cursor and no reaction to keystrokes). I can change the text selection with the mouse, but thatβs all.
Should I enable NSWindow to receive keystrokes?
Appreciate your help, - Josef
NSRect windowRect = [[self.window contentView] frame] ; NSWindow* uiWindow = [[NSWindow alloc] initWithContentRect:windowRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]; [uiWindow setBackgroundColor: [NSColor redColor]]; [uiWindow setOpaque:NO]; NSView* uiView = [[[NSView alloc] initWithFrame:NSMakeRect(0, 0, windowRect.size.width, windowRect.size.height)] autorelease]; [uiView translateOriginToPoint:NSMakePoint(100, uiView.bounds.size.height/2)]; uiView.wantsLayer = YES; [uiWindow setContentView:uiView]; NSTextField *textField; textField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 800, 80)]; [textField setFont:[NSFont fontWithName:@"Helvetica Bold" size:60]]; [textField setStringValue:@"My Label"]; [textField setBezeled:YES]; [textField setDrawsBackground:YES]; [textField setEditable:YES]; [textField setSelectable:YES]; [textField setEnabled:YES]; [uiView addSubview:textField];
PerfectGamesOnline.com
source share