UITextView autoscroll for the last row

When writing in a UITextView, more text than can completely fit inside it, the text will scroll up, and the cursor will often place one or two lines above the bottom line of the view. This is a little disappointing since I want my application to make good use of the entire height of the text view.

Basically I want to configure a UITextView to write the lowest part to it and not use it just for scrolling.

I saw several similar questions here and here . However, I have not yet seen the right solution.

thank

+3
source share
6 answers

( ), , UITextView. null scrollRectToVisible UITextView. :

- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated
{
// do nothing. This fixes the cursor jumping above the field defect.
}
+8

UITextView

-(void) setContentOffset:(CGPoint)contentOffset {
    [self setContentInset:UIEdgeInsetsZero];
    [super setContentOffset:contentOffset];
}

!

+2

NSRange myRange=NSMakeRange(outPutTextView.text.length, 0);

[outPutTextView scrollRangeToVisible:myRange];
+1

,

[textView setScrollEnabled:NO];

. , ... , , ( [textView text]) NO

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

UITextView, [[textView text] length] > maxCharacters.

0
source

I believe that the contentOffset property can also be used ...

0
source

I have the last line using setframe:

  • You can set the borders to about the height of the line
  • When you edit, in - (BOOL) textView:shouldChangeTextInRange:replacementText:, use scrollRangeToVisible:, argumentselectedRange
  • When you finish editing, setframe with original size
0
source

All Articles