How to paint background of specific range of text in NSTextView
Posted
by Rui Pacheco
on Stack Overflow
See other posts from Stack Overflow
or by Rui Pacheco
Published on 2010-05-11T20:29:34Z
Indexed on
2010/05/11
20:34 UTC
Read the original article
Hit count: 374
Hi,
This is not a specific bug, its more about not knowing how to do something.
I've an NSTextView and I need to paint the background of specific ranges of text when the user clicks on a specific part of the text view. I've tried this but I just get erratic behaviour in the sense that sometimes text loses the foreground color or the background doesn't span the whole range:
NSLayoutManager *layoutManager = [myTextView layoutManager];
[layoutManager removeTemporaryAttribute:NSBackgroundColorAttributeName
forCharacterRange:range];
[[myTextView layoutManager] setTemporaryAttributes:attributes forCharacterRange:range];
For the sake of simplicity assume that range is always a valid string (it is in my testing environment).
© Stack Overflow or respective owner