2013-10-15 17 views
9

Siyah bir arka plan üzerinde metin çizmeye çalışıyorum ve metnin işlenme biçiminde bazı farklılıklar görüyorum.Siyah bir arka plan üzerinde NSTextField ve NSTextView arasındaki farkları oluşturma

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 içindeki metin harika görünüyor ama NSTextView içindeki metin çok kalın görünür: İşte benim kod. Neyi yanlış yapıyorum?

enter image description here

+0

Neden hat 5,6,7 üzerinde TextField var? –

+0

Üzgünüz, kopyala ve yapıştır hata! – Aaron

cevap

0

NSTextField muhtemelen isteyebilirsiniz ne değildir koyu arka plan, konusundaki hücreyi anlatır:

Burada bir ekran görüntüsü var. Açık renk arka plan için işlemek için bunu söyle: Böyle çalıştık

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

Sorunu göstermek için ekran görüntüsü ekledim. NSTextField metni mükemmel bir şekilde işler. 'Yanlış' görünen NSTextView var. – Aaron

0

sadece bu satırı değiştirin: -

//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]; 
İlgili konular