加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – NSTextField颜色问题

发布时间:2020-12-16 03:12:02 所属栏目:百科 来源:网络整理
导读:我正在动态地添加一个NSTextField到一个窗口,我有渲染问题.我将背景颜色设置为黑色,文字颜色为白色.这两个工作都是工作,但它们似乎是一个长方形,它是始终是白色的文本的一部分.有谁知道我可能做错了什么?如何摆脱文本周围的白色背景?代码如下: //Create r
我正在动态地添加一个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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读