11

I'm trying to draw text onto a black background and I'm seeing some differences in the way the text is rendered. Here's my code:

NSTextView * textView = [[NSTextView alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, 500.0f, 50.0f)];
[textView setDrawsBackground:YES];
[textView setBackgroundColor:[NSColor blackColor]];
[textView setString:@"NSTextView: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."];
[textView setFont:[NSFont fontWithName:@"Helvetica" size:18.0f]];
[textView setEditable:NO];
[textView setTextColor:[NSColor whiteColor]];

[flippedView addSubview:textView];

NSTextField * textField = [[NSTextField alloc] initWithFrame:NSMakeRect(0.0f, 50.0f, 500.0f, 50.0f)];
[textField setDrawsBackground:YES];
[textField setBackgroundColor:[NSColor blackColor]];
[textField setBordered:NO];
[textField setBezeled:NO];
[textField setStringValue:@"NSTextField: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."];
[textField setFont:[NSFont fontWithName:@"Helvetica" size:18.0f]];
[textField setEditable:NO];
[textField setTextColor:[NSColor whiteColor]];

[flippedView addSubview:textField];

The text inside the NSTextField looks great but the text inside the NSTextView looks too bold. What am I doing wrong?

Here's a screenshot:

enter image description here

Aaron
  • 111
  • 4

2 Answers2

0

The NSTextField probably tells its cell about the dark background, which is not what you may want. Tell it to render for light background:

[[textField cell] setBackgroundStyle:NSBackgroundStyleLight];
Nikolai Ruhe
  • 81,520
  • 17
  • 180
  • 200
  • I've added a screenshot to show the problem. The NSTextField renders the text perfectly. It's the NSTextView that looks 'wrong'. – Aaron Oct 16 '13 at 09:19
0

I have tried like this just replace your this line:-

//replace below this line
    //[textView setFont:[NSFont fontWithName:@"Helvetica" size:18.0f]];
//Modified this below line
NSFontManager *fontManager = [NSFontManager sharedFontManager];
        NSFont *regular = [fontManager fontWithFamily:@"Helvetica"
                                                  traits:NSUnitalicFontMask
                                                  weight:0
                                                    size:18.0f];
        [textView setFont:regular];
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56