Tomasz Wojtkowiak
Tomasz Wojtkowiak

Reputation: 4920

Weird font behavior on the NSTextField

I added programmatically NSTextField to my NSView:

NSTextField *projectLabel = [[NSTextField alloc] initWithFrame:frame];
[projectLabel setStringValue:@"projectName"];
[projectLabel setBezeled:NO];
[projectLabel setDrawsBackground:NO];
[projectLabel setEditable:NO];
[projectLabel setSelectable:NO];

[projectLabel setFont:[NSFont controlContentFontOfSize:13]];
projectLabel.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin; 

[self addSubview:projectLabel];
[self setAutoresizesSubviews:NO];

This field was added correctly, but when I change size of view (or even move window to second display), font on field changes very weird (see attached image).

on start before
after change of the size after
I do not know what I did wrong

Upvotes: 2

Views: 386

Answers (1)

Peter Hosey
Peter Hosey

Reputation: 96323

I drew this label on drawRect every time, when the size changes.

So, you're manually telling the field to display in its parent view's drawRect:?

Don't do that. It's a subview, so it'll get told to draw in its turn anyway. Just let that happen.

Upvotes: 1

Related Questions