无法更改 NSButton 字体
我正在尝试更改我创建的 NSButton 子类的字体。当我使用以下代码设置实际按钮时,我可以设置字体:
[button setFont:[NSFont fontWithName:@"Courier" size:15]];
但是,当我稍后尝试在应用程序中执行此操作时,它不起作用。
我试图让用户选择一种新字体;一旦他们完成此操作,我想更新此按钮以使用所选字体。
我知道我的字体选择过程不是问题,因为我可以将其他 UI 项目的字体更改为用户选择的字体。
此外,我认为问题是由于我的子类正在经历 CABasicAnimation,但是当我删除动画时,它仍然不起作用。此外,我什至可以在动画运行时更改按钮的字体颜色。
最后,我确定我的插座连接正确。
那么问题可能出在哪里呢?过去有人遇到过类似的问题吗?
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.
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您检查 IB 连接,因为
setFont:
应该可以工作。或者您可以尝试使用:
其中
NSAttributedString
可以创建自:其中属性可以创建为:
I would recommend you check your IB connections cause
setFont:
should work.Or you could try using:
where an
NSAttributedString
can be created from:where attributes can be created as: