使用NSTextField创建标签是模糊的 [英] Creating a label using NSTextField is blurry

查看:653
本文介绍了使用NSTextField创建标签是模糊的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用NSTextField以编程方式创建标签,但它模糊不清:截图

I'm trying to create a label programmatically using NSTextField, but it comes out blurry: screenshot

这是我到目前为止的代码:

This is my code so far:

NSTextfield *textfield = [[NSTextField alloc] initWithFrame:NSMakeRect(5,5,150,20)];
[texField setStringValue:@"some text here"];
[textField setEditable:NO];
[textField setSelectable:NO];
[textField setBordered:NO]
[textField setDrawsBackground:NO]



将问题追溯到setDrawsBackground行。我也试过使用[textField setBackgroundColor:[NSColor clearColor],但没有运气。

I've traced the problem down to the setDrawsBackground line. I've also tried using [textField setBackgroundColor:[NSColor clearColor] as well, but no luck.

顺便说一句,我已经添加到一个textField子视图视图是一个scrollview的子视图。我也在所有视角级别上使用isOpaque,但没有运气了。

By the way, I've adding to a textField to the subview of a view that is a subview of a scrollview. I've also playing with isOpaque on all the view levels, but no luck there again.

任何帮助是非常感谢。

Any help is greatly appreciated.

推荐答案

由于这是我第一次子类化NSView,我把上面的代码放在 drawRect 方法,而不是 initWithFrame 方法。我这样做是因为我是从苹果的开发网站下面的示例应用程序之一。

Since this was my first time subclassing NSView, I had put the above code in the drawRect method instead of the initWithFrame method. I did this because I was following one of the sample applications from Apple's Dev site.

这也导致我的CPU使用率,当我滚动

This was also causing my CPU usage to spike when I was scrolling

这篇关于使用NSTextField创建标签是模糊的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆