2010-08-31 172 views
0

我正在从NSFontPanel检索一个值,该值更改字体系列,文本样式。但我只想分开选择从NSFontPanel中选择的字体样式和颜色。如何从字体面板(NSFontPanel)中检索字体样式(粗体,斜体,粗斜体)和颜色?

我没有得到如何得到。

NSFont *font =[fontmanager selectedFont]; 
    string =[font fontName]; 
    st = [font pointSize]; 
    color =[TextEntered textColor]; 
  1. 在字符串变量我越来越字体家族(e.g.Arial)和字体样式(如粗体)。但我需要单独的这些值。

  2. 而在颜色变量我只会得到黑色。

我不能够理解我的错在获得颜色,我用什么函数获取字体样式..

回答

0

获取其风格,你会使用[fontmanager traitsOfFont: font]。至于颜色,我认为你想要得到的文本为NSAttributedString,然后获得属性NSForegroundColorAttributeName的值。

编辑补充:假设你的TextEntered变量的NSTextField *,使用这样的:

NSAttributedString* theText = [TextEntered attributedStringValue]; 
NSColor* theColor = (NSColor*)[theText attribute: NSForegroundColorAttributeName 
    atIndex: 0 effectiveRange: NULL ]; 

对于删除线,使用NSStrikethroughStyleAttributeName和下划线使用NSUnderlineStyleAttributeName

+0

你会PLZ给我一个例子.. – 2010-08-31 07:14:35

+0

获取颜色的例子。并感谢您回答..它可以获取字体样式。 – 2010-08-31 07:27:56

+0

,你会plz也告诉我如何通过NSFontPanel获取穿透和强调。 – 2010-08-31 07:29:10

相关问题