0

Let me elaborate the steps i am doing

  1. Create Mac 10.9 Project
  2. Drag a CustomView (Let's call it myView) to the .xib
  3. Drag a NSButton to the .xib but out side the CustomView
  4. Now programatically (using a other class) i add a NSTextField to the CustomView when the button is clicked by this code

    NSTextField *textField = [[NSTextField alloc] init]; [textField setBezeled:NO]; [textField setEditable:NO]; [textField setSelectable:NO]; [textField setFont:[NSFont fontWithName:@"Arial" size:20]]; [textField setStringValue:@"Hello World!"]; int textWidth = textField.fittingSize.width; int textHeight = textField.fittingSize.height; [textField setFrame:NSMakeRect(0, 0, textWidth, textHeight)]; [myView addSubview:textField];

  5. Now i see that the TestField is added to myView

  6. All i want is the user can drag the textField movable inside myView

i added the following code

- (void)mouseDown:(NSEvent *)event{
    NSLog(@"Hi");
}

But the NSLog is not getting shown

How do i make the NSTextField draggable?

user226372
  • 165
  • 1
  • 9

1 Answers1

0

Note: Because mouse-moved events occur so frequently that they can quickly flood the event-dispatch machinery, an NSWindow object by default does not receive them from the global NSApplication object. However, you can specifically request these events by sending the NSWindow object an setAcceptsMouseMovedEvents: message with an argument of YES.

From Apple Docset

Jelle De Laender
  • 577
  • 3
  • 16