2013-10-15 96 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文本框? –

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