0

Hello I'm trying to create a custom text editor, for which I want to know the position of the cursor and range of the text in UITextView for which I can apply TextAttributes based on the user selected options.

For eg:

\n This is a the first paragraph string \n This is the second paragraph string \n

For this string, if the cursor is anywhere in the first paragraph string, and user select some text attribute, then I want to change only the This is a the first paragraph string based on selection.

For now, I know this can be achieved using multiple text attributes for specific range.I'm unable to get the range based on the cursor and break characters.

I'm new to this. If there is some other way to achieve this please let me know. Thanks

timbre timbre
  • 12,648
  • 10
  • 46
  • 77
NewUser
  • 21
  • 3
  • Welcome to Stack Overflow! Please take the [tour](https://stackoverflow.com/tour) and see: [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) and [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). – Yrb Nov 23 '21 at 14:00
  • `selectedRange` (https://developer.apple.com/documentation/uikit/uitextview/1618615-selectedrange ) property of the `UITextView` should do the trick, no ? Then, some manipulation to know where to expand your selection might be done. – Larme Nov 23 '21 at 14:08
  • This question is too big. Try to write some code step by step, and ask questions on specific hurdles you hit. For example start from writing a function that can find a paragraph, defined by new line character in UITextView. Step 2 - write a function that changes attributes for a given portion of the text inside UITextView. Once you have those 2 functions, you can pass results of the first one (found paragraph) to the second one – timbre timbre Nov 23 '21 at 16:38

0 Answers0