2

I have a UITextView that I want to be scrollable. The problem right now, is that the keyboard appears so the user can only enter comments into the first half of the screen. What I want is the TextView to be scrollable so the user can enter new information.

This is the code I am using:

[comments setScrollEnabled:YES];
[comments setUserInteractionEnabled:YES];

Not sure what I am missing. I see no scrollbars.

Any help appreciated.

Johnny Rottenweed
  • 317
  • 1
  • 6
  • 16

5 Answers5

4

UITextView became scrollable only when text exceed the frame. You can't scroll it if the text fits inside the frame.

Fry
  • 6,036
  • 8
  • 48
  • 89
3

You need to resize the UITextView so it fits in the area above the keyboard. The text will automatically scroll within the text view if the text is too big to fix in the displayed area.

Apple has a document that covers this. See Moving Content That Is Located Under the Keyboard.

rmaddy
  • 298,130
  • 40
  • 468
  • 517
0

Embed your UITextView within a UIScrollView then check this link, I may be helpful.

Community
  • 1
  • 1
Mousa
  • 2,377
  • 22
  • 33
  • I tried putting a UIScrollView underneath the UITextView. Is that what you mean by emdedding? Didn't work for me. Can you explain more? Also, I've used the link you suggested before for UITextFields but ASFAIK this code does not work for UITextViews.... – Johnny Rottenweed Nov 02 '12 at 00:16
  • `UITextView` is a scroll view. You don't put it in another one. – rmaddy Nov 02 '12 at 01:14
  • But how to allow the user to scroll without the keyboard hiding what is beneath? This code kinda works but the keyboard is still in the way. I wish the textview would scroll down to allow more input. self.directions.scrollEnabled = YES; self.directions.userInteractionEnabled = YES; self.directions.alwaysBounceVertical = YES; self.directions.delegate = self; – Johnny Rottenweed Nov 02 '12 at 01:39
  • @JohnnyRottenweed See the answer I just posted. – rmaddy Nov 02 '12 at 02:55
  • What I meant is adding the UITextView to a UIScrollView as a sub view for it, then apply the code in the link posted and you're good. – Mousa Nov 03 '12 at 09:43
0

the UITextView class is a subclass of UIScrollView , so it inherits the same behavior . So if the content size of the text view is greater than its bounds then only the text view will be scrollable . So one thing you can do is that make the bounds of the text view bit small , so that the text view can scroll.Refer this link for reference

Community
  • 1
  • 1
Singh
  • 1,882
  • 2
  • 14
  • 30
0

I had a button to activate the scroll feature and the following worked for me.

@IBOutlet var NotePadTextField: UITextView!

@IBAction func ClickOnNotePadTextView(_ sender: UIButton) {
    NotePadTextField.isScrollEnabled = true
    NotePadTextField.alwaysBounceVertical = true
    NotePadTextField.isUserInteractionEnabled = true
}
DeeNove750
  • 43
  • 8