Dynamic text labels in NIB file
-
05-07-2019 - |
Question
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
Solution
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.
OTHER TIPS
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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow