无法更改NSButton字体 [英] Can't Change NSButton Font

查看:231
本文介绍了无法更改NSButton字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改我创建的NSButton子类的字体。我可以使用以下代码设置实际按钮时设置字体:

I'm trying to change the font of a NSButton subclass I've created. I'm able to set the font up when I set up the the actual button using the following code:

    [button setFont:[NSFont fontWithName:@"Courier" size:15]];

但是,当我试图在我的应用程序中做它,它不工作。

However, when I'm trying to do it later on in my application, it doesn't work.

我想让用户选择一种新的字体;一旦他们这样做,我想更新此按钮使用所选的字体。

I'm trying to get the user to select a new font; once they've done this, I want to update this button to use the selected font.

我知道我的字体选择过程不是问题,因为我可以将其他UI项目的字体更改为用户选择的字体。

I know my font-selection process isn't the issue, as I can change the font of other UI items to what the user's chosen.

此外,我认为问题是由于我的子类正在经历一个CABasicAnimation,我删除动画,它仍然不工作。此外,我甚至可以在动画运行时更改按钮的字体颜色。

Additionally, I thought the problem was due to the fact that my subclass is going through a CABasicAnimation, but when I remove animations, it still doesn't work. Furthermore, I can even change the button's font color while the animation is running.

最后,我确定我的插座已正确连接。

Finally, I'm certain my outlets are connected right.

那么问题来自哪里呢?

So where could the problem be coming from? Has anyone experienced a similar issue in the past?

推荐答案

我建议您检查您的IB连接,因为 setFont:应该可以工作。

I would recommend you check your IB connections cause setFont: should work.

或者您可以尝试使用:

(void)setAttributedTitle:(NSAttributedString *)aString

c $ c> NSAttributedString 可以创建自:

where an NSAttributedString can be created from:

- (id)initWithString:(NSString *)aString attributes:(NSDictionary *)attributes

其中可以创建属性:

NSDictionary * attributes = [NSDictionary dictionaryWithObject:[NSFont fontWithName:@"Courier" size:15] forKey:NSFontAttributeName];

这篇关于无法更改NSButton字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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