C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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上尝试过你的代码. @H_502_8@在应用程序委托中:

- (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];
}
@H_502_8@这就是结果

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

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

大佬总结

以上是大佬教程为你收集整理的objective-c – NSTextField颜色问题全部内容,希望文章能够帮你解决objective-c – NSTextField颜色问题所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。