Johnny Rottenweed
Johnny Rottenweed

Reputation: 337

UITextView: How to make scrollable?

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.

Upvotes: 2

Views: 3224

Answers (5)

DeeNove750
DeeNove750

Reputation: 63

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
}

Upvotes: 0

Singh
Singh

Reputation: 2161

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

Upvotes: 0

rmaddy
rmaddy

Reputation: 318774

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.

Upvotes: 3

Fry
Fry

Reputation: 6275

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

Upvotes: 4

Mousa
Mousa

Reputation: 3036

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

Upvotes: 0

Related Questions