Indent only the first line of a UITextView?
I'd like to indent the first l开发者_开发知识库ine of a uitextview, but haven't find a way to do this. I'd think it would be possible since it's a pretty common paragraph behavior..
Try this, it will insert 4 spaces at the beginning of the first line of the textView (not at the first line of each paragraph, I'm not sure which you wanted?)
textView.text = [textView.text stringByReplacingCharactersInRange:NSMakeRange(0,0) withString:@" "];
To Prevent the user from moving the selection point to the indent:
Set the textview's delegate and implement the textViewDidChangeSelection:
method
Then in the method, do something like:
if (textView.selectedRange.location < 4) {
textView.selectedRange = NSMakeRange(4, 0)
}
精彩评论