简体   繁体   中英

Can't Change NSButton Font

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?

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM