简体   繁体   中英

NSButton(Cell) setFont

It seems that NSButtonCell 's setFont method is not available anymore from 10.9.
Is there any way (or category) to (re)implement it?

I don't know why Apple forces it's own styles on buttons.
I am trying for 2 days to style my own custom button (I also needed a category to simply change the button's text color - shame).

You can use -setAttributedTitle: of NSButton to set the style of button title.

Sample code:

NSDictionary *attributes = @{NSForegroundColorAttributeName: [NSColor redColor], NSFontAttributeName: [NSFont userFixedPitchFontOfSize:13.0f]};
NSAttributedString *aString = [[NSAttributedString alloc] initWithString:@"Button" attributes:attributes];
[button setAttributedTitle:aString];

在此处输入图片说明

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