2013-10-15 16 views
9

黒い背景にテキストを描画しようとしていますが、テキストのレンダリング方法にいくつかの違いがあります。私のコードは次のとおりです:黒い背景にNSTextFieldとNSTextViewのレンダリングの違い

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]; 

NSTextField内のテキストは素晴らしいようですが、NSTextView内のテキストは太字に見えます。私は間違って何をしていますか?

がここにスクリーンショットです:

enter image description here

+0

は、なぜあなたはライン5,6,7上のTextFieldを持っていますか? –

+0

申し訳ありません、コピー&ペーストエラーです! – Aaron

答えて

0

NSTextFieldはおそらくあなたが望むかもしれないものではない暗い背景、についてそのセルを伝えます。明るい背景のためにレンダリングするためにそれを教える:私はこのような試みている

[[textField cell] setBackgroundStyle:NSBackgroundStyleLight]; 
+0

問題を表示するためのスクリーンショットを追加しました。 NSTextFieldはテキストを完全にレンダリングします。 「間違っている」と思われるのはNSTextViewです。 – Aaron

0

ちょうどあなたの次の行を置き換える: -

//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]; 
関連する問題