objective-c – NSTextField颜色问题

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

NSRect textFieldRect = NSMakeRect(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];

解决方法

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

在应用程序委托中:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    NSRect textFieldRect = NSMakeRect(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];
}

这就是结果

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

我看不到任何白盒子.也许你正在使用不同的操作系统.或者也许你有一些其他的观点,相互引起你正在谈论的奇怪的影响.

相关文章

对象的传值与返回说起函数,就不免要谈谈函数的参数和返回值...
从实现装饰者模式中思考C++指针和引用的选择最近在看...
关于vtordisp知多少?我相信不少人看到这篇文章,多半是来自...
那些陌生的C++关键字学过程序语言的人相信对关键字并...
命令行下的树形打印最近在处理代码分析问题时,需要将代码的...
虚函数与虚继承寻踪封装、继承、多态是面向对象语言的三大特...