0

I created a nib file and want to display dynamic text messages on it like file names that are selected or the no of files selected etc. Is there a way to to this?

I know this can be done for alert panels but i want it on my custom sheets.

Thanks

Abizern
  • 146,289
  • 39
  • 203
  • 257
King
  • 239
  • 3
  • 17

2 Answers2

3

Either create connections between your NSTextField elements and your controller class and then set the labels programmatically (using setStringValue).

Or you could consider using bindings. See http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaBindings/CocoaBindings.html.

Chris Suter
  • 2,897
  • 2
  • 19
  • 10
3

You can create a NSTextField programmatically like this:

(IBAction)showText:(id)sender {
    NSRect frame = NSMakeRect(50, 50, 200, 100);
    NSTextField *tf = [[NSTextField alloc] initWithFrame:frame];
    [tf setStringValue:@"test"];
    [tf setSelectable:NO];
    [tf setEditable:NO];
    [tf setBordered:NO];
    [tf setDrawsBackground:NO];
    [[[sender window] contentView] addSubview:tf];
    [tf release];
}

or you could use NSString's methods for drawing text in a view, namely -drawAtPoint or -drawInRect

Woofy
  • 3,751
  • 1
  • 14
  • 12