3

When writing in a UITextView more text than can fit entirely inside it, the text will scroll up and the cursor will often place itself one or two lines above the view's bottom line. This is a bit frustrating as I want my application to make good use of the entire height of the text view.

Basically what I want is to configure the UITextView to write up to it's lowest part and not use it just for scrolling.

I've seen some similar questions here, here and here. However I've not seen a proper solution yet.

Thanks

Community
  • 1
  • 1
Mihai Damian
  • 11,193
  • 11
  • 59
  • 81

6 Answers6

8

I've a slightly different implementation (I want to disable scrolling), but I also had to stop the cursor jumping out of my UITextView. To do this, I implemented a null scrollRectToVisible in my UITextView subclass. Like this:

- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated
{
// do nothing. This fixes the cursor jumping above the field defect.
}
Jane Sales
  • 13,526
  • 3
  • 52
  • 57
  • That's a good hint. I can probably re-implement this method to make the text view auto scroll exactly the way I need it. – Mihai Damian Dec 17 '09 at 14:46
2

excellent solution is in subclass UITextView add lines

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

It's work!

Zeine
  • 21
  • 1
1

use this

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

[outPutTextView scrollRangeToVisible:myRange];
Ashok
  • 5,585
  • 5
  • 52
  • 80
0

I've got the last line by setframe :

  1. You can setframe to about a line height
  2. When you are editing, in - (BOOL)textView:shouldChangeTextInRange:replacementText:,use scrollRangeToVisible:,the argument is selectedRange
  3. When you end edit, setframe to the original size
Diego D
  • 1,735
  • 3
  • 22
  • 38
0

if I understand right, you can use

[textView setScrollEnabled:NO];

to disable scrolling. what about not to type when the cursor reached the lower margin... maybe it is not good solution but you can add some threshold value(maximum characters in the [textView text]) and return NO in

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

delegate method of UITextView if [[textView text] length] > maxCharacters.

Morion
  • 10,495
  • 1
  • 24
  • 33
  • Perhaps I was not clear. I still want the view to be scrollable. But I also want to be able to write text on it's entire height. This is something that's not generally possible by default since the text will start bouncing up when you hit the last but least line (and I can tell the UITextView extends below this line by scrolling the text downwards). – Mihai Damian Nov 27 '09 at 19:33
0

I find seem the property 'contentOffset' also can be use ...

iXcoder
  • 1,564
  • 4
  • 20
  • 41