I am having problems positioning my NSTextFields inside my views so I hope you guys can help me. I have this NSView *theView with [theView setFrame:NSMakeRect(10, 10, 64, 64)];
which positions the view exactly where I want it.
But now I am trying to add a NSTextField as a subView to theView but something isn't right. Now the image above is how it should be.
Here's my code and what it looks like:
primaryDigit = [[NSTextField alloc] init];
[primaryDigit setFrame:NSMakeRect(4, 6, 60, 58)];
[primaryDigit setFont:[NSFont fontWithName:@"Helvetica Neue" size:55]];
[primaryDigit setBezeled:NO];
[primaryDigit setEditable:NO];
[primaryDigit setSelectable:NO];
[primaryDigit setDrawsBackground:NO];
[primaryDigit setTextColor:[NSColor whiteColor]];
[primaryDigit setStringValue:@"2"];
[self addSubview:primaryDigit];
And when I do [primaryDigit setFrame:NSMakeRect(0, 0, 64, 64)];
the digit doesn't end up in the left lower corner but it does this:
Is there something fundamental that I don't understand about positioning these views? I'm quite the noobie but I still thought that I understand this. (Btw, the font is different in these images but that shouldn't cause a problem, I think?)
Update: as 'dasdom' asked me to, here's the text field with a background colour
[self addSubview:primaryDigit];
is in thetheView
class, right? – Alexander