UITextView - 设置最大行隐藏光标

Nit*_*ish 8 uitextview ios swift

这就是我要设置的最大行数:

self.text_description.textContainer.maximumNumberOfLines = 2
self.text_description.layoutManager.textContainerChangedGeometry(self.text_description.textContainer)  
Run Code Online (Sandbox Code Playgroud)

当第3行即将开始时,光标消失.要把它放回去,我必须点击退格键.

byJ*_*van 3

Assuming, in the text view cursor doesn't stays behind the keyboard. I have written a helper method that makes UITextField text scroll to end of text.

- (void)scrollToCaretInTextView:(UITextView *)textView animated:(BOOL)animated
{
    CGRect rect = [textView caretRectForPosition:textView.selectedTextRange.end]; //Get the content size of textview 
    rect.size.height += textView.textContainerInset.bottom;
    [textView scrollRectToVisible:rect animated:animated];
}
Run Code Online (Sandbox Code Playgroud)