tags:

views:

30

answers:

1

I am retrieving value from NSFontPanel,which changes the font family,style of Text. But I want only Font Style and color separately that I have selected from NSFontPanel.

i am not getting how to get that.

NSFont *font =[fontmanager selectedFont]; string =[font fontName]; st = [font pointSize]; color =[TextEntered textColor];

  1. In string variable I am getting Font family(e.g.Arial) and Font style(e.g. Bold). but I want these values separately.

  2. And in color variable I only get black color.

I am not able to understand where I am wrong in getting color,and what function I used for getting font style..

A: 

To get the style, you would use [fontmanager traitsOfFont: font]. As for the color, I think you want to get the text as an NSAttributedString and then get the value for the attribute NSForegroundColorAttributeName.

Edit to add: Assuming that your TextEntered variable is NSTextField*, use something like this:

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

For strikethrough, use NSStrikethroughStyleAttributeName and for underline use NSUnderlineStyleAttributeName.

JWWalker
will you plz give me one example..
Greshi Gupta
example of getting color. and thanks for answering..it works for getting font style.
Greshi Gupta
and will you plz also tell me how to get strike through and underline from NSFontPanel.
Greshi Gupta
thanks, it works fine.
Greshi Gupta