Search code examples
objective-ccocoanstextfield

Creating a label using NSTextField is blurry


I'm trying to create a label programmatically using NSTextField, but it comes out blurry: screenshot

This is my code so far:

NSTextfield *textfield = [[NSTextField alloc] initWithFrame:NSMakeRect(5,5,150,20)];
[texField setStringValue:@"some text here"];
[textField setEditable:NO];
[textField setSelectable:NO];
[textField setBordered:NO]
[textField setDrawsBackground:NO]

I've traced the problem down to the setDrawsBackground line. I've also tried using [textField setBackgroundColor:[NSColor clearColor] as well, but no luck.

By the way, I've adding to a textField to the subview of a view that is a subview of a scrollview. I've also playing with isOpaque on all the view levels, but no luck there again.

Any help is greatly appreciated.


Solution

  • Since this was my first time subclassing NSView, I had put the above code in the drawRect method instead of the initWithFrame method. I did this because I was following one of the sample applications from Apple's Dev site.

    This was also causing my CPU usage to spike when I was scrolling