我正在从NSFontPanel中检索一个值,它会更改字体系列、文本样式。但我只想要字体风格和颜色,我已经选择了从NSFontPanel。
我不知道该怎么做。
NSFont *font =[fontmanager selectedFont];
string =[font fontName];
st = [font pointSize];
color =[TextEntered textColor];字符串变量中的
,
我无法理解我在获得颜色方面的错误之处,以及我用来获得字体样式的功能。
发布于 2010-08-31 06:18:12
要获得这种风格,您可以使用[fontmanager traitsOfFont: font]。至于颜色,我认为您希望将文本作为NSAttributedString,然后获取属性NSForegroundColorAttributeName的值。
编辑以添加:假设您的TextEntered变量是NSTextField*,请使用如下所示:
NSAttributedString* theText = [TextEntered attributedStringValue];
NSColor* theColor = (NSColor*)[theText attribute: NSForegroundColorAttributeName
atIndex: 0 effectiveRange: NULL ];对于删除,使用NSStrikethroughStyleAttributeName和下划线使用NSUnderlineStyleAttributeName。
https://stackoverflow.com/questions/3606329
复制相似问题