Indent only the first line of a UITextView?

I would like to delay the first line of uitextview, but have not found a way to do this. I would have thought it would be possible, as this is a fairly common paragraph behavior.

+3
source share
1 answer

Try this, it inserts 4 spaces at the beginning of the first line of the textView (not in the first line of each paragraph, I'm not sure what you wanted?)

textView.text = [textView.text stringByReplacingCharactersInRange:NSMakeRange(0,0) withString:@"    "];

To prevent the user from indenting the selection point:

Set a textview delegate and make a textViewDidChangeSelection:method

Then in the method do something like:

if (textView.selectedRange.location < 4) {
    textView.selectedRange = NSMakeRange(4, 0)
}
+3
source

Source: https://habr.com/ru/post/1793298/


All Articles