views:

18

answers:

2

I am dynamically adding a NSTextField to a window and am having issues with rendering. I am setting the background color to be black and the text color to be white. These both work but their is what appears to be a rectangle that is part of the text that is always white. Does anyone know what I might be doing wrong? How can I get rid of the white background that is just around the text? Code is as follows:

//Create rectangle to size text field

NSRect textFieldRect = NSMakeRect(300, 300, 300, 54);

//Instantiate text field and set defaults NSTextField* textField = [[NSTextField alloc] initWithFrame:textFieldRect];

[textField setFont:[NSFont fontWithName:@"Arial" size:48]];

[textField setTextColor:[NSColor whiteColor]];

[textField setStringValue:@"Some Text"];

[textField setBackgroundColor:[NSColor blackColor]];

[textField setDrawsBackground:YES];

[textField setBordered:NO];

[[window contentView] addSubview:textField];

Thanks,

JTC

A: 

I tried your code on Mac OS X 10.6.4.

Inside the application delegate:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    NSRect textFieldRect = NSMakeRect(300, 300, 300, 54);
    NSTextField* textField = [[NSTextField alloc] initWithFrame:textFieldRect];
    [textField setFont:[NSFont fontWithName:@"Arial" size:48]];
    [textField setTextColor:[NSColor whiteColor]];
    [textField setStringValue:@"Some Text"];
    [textField setBackgroundColor:[NSColor blackColor]];
    [textField setDrawsBackground:YES];
    [textField setBordered:NO];
    [[window contentView] addSubview:textField];
}

And this is the result

alt text

I can't see any white box.
Maybe you are using a different OS.
Or maybe you have some other views on top of each other that are causing the weird effect you are talking about.

Florin
Thanks for the quick response Florin, maybe something that is important, I am adding the NSTextField to a dynamically created NSWindow that has a black background. Not sure if that makes a difference but it must considering you don't seem to be having the same problem I am.
A: 

Ok,

The mystery is partially solved. In conjunction with my NSTextField, I am also setting some NSApplicationPresentationOptions to put the application into Kiosk mode. It appears that something with that is causing the problem I am seeing. If I do not set the PresentationOptions the NSTextField displays exactly the way I want it to. I will track down what specific PresentationOption is to blame and post here.

It appears that the call to [NSApp setPresentationOptions: ]is to blame. Even if I call it setting it to the default, it will cause the text to have a white background. Hmm.....