Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Give Attributes to Specific TextView Index Range
-
My last post consisted of me asking how to give attributes to characters you are currently typing.
This thread's about how to give attributes to a specific range of text in a TextView object. I already understand how to give attributed text to the characters you are typing, but not to the ones already typed. This is my big issue.
If anyone could show me some examples, and give insights, it would be very much appreciated.
Thanks,
Sean
-
you will want to take a look at
addAttibutes_range_
will let you add an attribute -- first argument is a dictionary of attributes, second is a NSRange object, which can be created by NSRange(start, length).
you can also useaddAttribute_value_range_
where you use a single string attribute name and value rather than packed in a dictionary.Also of interest may be the corresponding removeAttribute... and setAttribute... methods.
I am not sure, but you might need to preceed these with a
beginEditing
and end withendEditing
, and might need to useon_main_thread
. Also, this needs to be a NSMutableAttributedAtring, which is writable. -
Oh, you're a life saver. Thank you so much. I was looking all over the developer website and couldn't find that.