NSTextField颜色问题

Joh*_*ate 9 objective-c nstextfield

我正在动态添加一个NSTextField窗口,我有渲染问题.我将背景颜色设置为黑色,将文本颜色设置为白色.这些都可以工作,但它们似乎是一个矩形,它是文本的一部分,始终是白色的.有谁知道我可能做错了什么?如何摆脱文本周围的白色背景?代码如下:

//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];
Run Code Online (Sandbox Code Playgroud)

Flo*_*rin 11

我在Mac OS X 10.6.4上尝试了你的代码.

在应用程序委托内:

- (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];
}
Run Code Online (Sandbox Code Playgroud)

这就是结果

alt text http://www.freeimagehosting.net/uploads/26c04b6b64.png

我看不到任何白盒子.
也许你正在使用不同的操作系统.
或者你可能还有一些其他的视图,这些视图会导致你所讨论的奇怪效果.