Пример кода для создания NSTextField “маркировка”?

IIRC, у Вас будет IrreversibleMigration при изменении типа данных в миграции.

51
задан Todd Ditchendorf 1 October 2009 в 16:36
поделиться

4 ответа

A label is actually an instance of NSTextField, a subclass of NSView. So, since it is a NSView, it has to be added to another view.

Here's a working code:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    NSTextField *textField;

    textField = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 10, 200, 17)];
    [textField setStringValue:@"My Label"];
    [textField setBezeled:NO];
    [textField setDrawsBackground:NO];
    [textField setEditable:NO];
    [textField setSelectable:NO];
    [view addSubview:textField];
}
115
ответ дан 7 November 2019 в 09:47
поделиться

This can be tricky to get right. I don't have the recipe for an exact replica handy, but when I've been stuck in a similar situation, here's what I do:

  1. Create a UI element in IB.
  2. Add an outlet to it from my controller class.
  3. Break in gdb in awakeFromNib or whatever.
  4. From the gdb prompt, "p *whateverOutlet" ... this will show you the C struct contents of the label NSTextField that IB set up.

By looking at all the myriad values in there, you can get a lot of guesses about what you're neglecting to set. Usually it ends up being some magic combination of bezel and border settings, that gets you where you want to be.

8
ответ дан 7 November 2019 в 09:47
поделиться

Specifically, you will want to setBordered:NO, and set the bezel style to whatever that bezel style is which I forgot. Also setEditable:NO, and optionally setSelectable:NO. That should suffice.

2
ответ дан 7 November 2019 в 09:47
поделиться

You could try using nib2objc to get all the properties that IB sets

5
ответ дан 7 November 2019 в 09:47
поделиться