Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 1.42 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. NSTextField not editable in custom NSWindow
  2. NSRect windowRect = [[self.window contentView] frame] ;
  3.       NSWindow* uiWindow          = [[NSWindow alloc]  initWithContentRect:windowRect
  4.                     styleMask:NSBorderlessWindowMask
  5.                     backing:NSBackingStoreBuffered defer:YES];
  6.       [uiWindow setBackgroundColor: [NSColor redColor/*clearColor*/]];
  7.       [uiWindow setOpaque:NO];
  8.  
  9.       NSView* uiView = [[[NSView alloc] initWithFrame:NSMakeRect(0, 0, windowRect.size.width, windowRect.size.height)] autorelease];
  10.       [uiView translateOriginToPoint:NSMakePoint(100, uiView.bounds.size.height/2)];
  11.       uiView.wantsLayer = YES;
  12.  
  13.       [uiWindow setContentView:uiView];
  14.  
  15.       NSTextField *textField;
  16.       textField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 800, 80)];
  17.       [textField setFont:[NSFont fontWithName:@"Helvetica Bold" size:60]];
  18.       [textField setStringValue:@"My Label"];
  19.       [textField setBezeled:YES];
  20.       [textField setDrawsBackground:YES];
  21.       [textField setEditable:YES];
  22.       [textField setSelectable:YES];
  23.       [textField setEnabled:YES];
  24.  
  25.       [uiView addSubview:textField];
  26.  
  27.  
  28. // THIS DOES NOT WORK
  29. [self.window addChildWindow:uiWindow ordered:NSWindowAbove];
  30.  
  31. // THIS WORKS
  32. //[_graphicView addSubview:uiView];
  33.        
  34. - (BOOL)canBecomeKeyWindow
  35. {
  36.     return YES;
  37. }
  38.        
  39. if([uiWindow isKeyWindow] == TRUE) {
  40.     NSLog(@"isKeyWindow!");
  41. }
  42. else {
  43.     NSLog(@"It's not KeyWindow!");
  44. }