开发者

Getting the Current font of a NSTextView

开发者 https://www.devze.com 2022-12-18 19:55 出处:网络
How would I get the current font of an NSTextView开发者_Go百科?Peter\'s answer is correct but is not the whole story. Calling -font on the NSTextView will return the font of the first character in the

How would I get the current font of an NSTextView开发者_Go百科?


Peter's answer is correct but is not the whole story. Calling -font on the NSTextView will return the font of the first character in the text view's string, or if the text view is empty it will return the font at the insertion point.

However, if the text view is configured to accept rich text, the text view can have several different fonts.

In that case, you would need to obtain the font from a specific location in the text view's NSTextStorage object, which is a subclass of NSAttributedString. You obtain the NSTextStorage object by calling -textStorage on the text view.

You can get the font at a particular location in the NSTextStorage object by using the -attribute:atIndex:effectiveRange: method of NSAttributedString and passing in NSFontAttributeName for the attribute parameter.


An NSTextView is a kind of NSText. So, send it a font message.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号