我有一个应用程序,我的用户需要修改样式(字体,大小,粗体,背景色,.)如何在FontPanel中加载初始样式并在用户验证后获得新属性?
我尝试了很多不同的东西,但都没有成功。
谢谢
发布于 2015-01-20 18:27:22
使用setPanelFont:isMultiple:设置最初选定的字体。
使用[NSFontManager sharedFontManager] setSelectedAttributes:isMultiple:更改初始颜色;字典键是NSForegroundColorAttributeName和@"NSDocumentBackgroundColor"表示颜色,NSUnderlineStyleAttributeName和NSStrikethroughStyleAttributeName表示样式。
当字体更改时,将调用委托实例的changeFont:方法。
同调样式:changeAttributes:方法。以及文本和文档颜色:setColor:forAttribute:方法。
要获取changeAttributes方法中的新属性,请执行以下操作:
NSDictionary * newAttributes = [sender convertAttributes:@{}];发布于 2020-07-06 15:54:42
Swift 4.2:
NSFontPanel.shared.setPanelFont(myNSFont, isMultiple: false)
NSFontManager.shared.setSelectedAttributes([NSAttributedString.Key.foregroundColor.rawValue: myNSColor], isMultiple: false)您可以找到所有属性键的列表( 这里 )--旧的样式常量还没有被废弃,但是从10.13开始就不再工作了。
要获得更改通知(例如,如果要更改没有附加字段编辑器的标签的内容),需要设置NSFonManager.Shared的目标和操作,并注册NSColorPanel.colorDidChangeNotification (NSColorChanging在从FontPanel打开ColorPanel时不触发)。
https://stackoverflow.com/questions/28014768
复制相似问题