omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    2
    3
    2163
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • AtomBombed
      AtomBombed last edited by AtomBombed

      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

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        you will want to take a look at

        https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSMutableAttributedString_Class/index.html#//apple_ref/occ/instm/NSMutableAttributedString/

        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 use addAttribute_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 with endEditing, and might need to use on_main_thread. Also, this needs to be a NSMutableAttributedAtring, which is writable.

        1 Reply Last reply Reply Quote 0
        • AtomBombed
          AtomBombed last edited by

          Oh, you're a life saver. Thank you so much. I was looking all over the developer website and couldn't find that.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors