Can't Change NSButton Font

元气小坏坏 提交于 2019-12-08 04:28:25

问题


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?


回答1:


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

Or you could try using:

(void)setAttributedTitle:(NSAttributedString *)aString

where an NSAttributedString can be created from:

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

where attributes can be created as:

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


来源:https://stackoverflow.com/questions/9137881/cant-change-nsbutton-font

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!