iOS — UITextView disable scrolling but enable touches

0 votes
asked Dec 10, 2010 by william-jockusch

Is there any way to do this?

What I really want is a UITextField where I can control the location of the cursor. But as far as I can tell, that is impossible. So I am looking at using a UITextView. This does allow one to control the cursor location. But scrolling is getting in the way -- my text is scrolling here and there, and I don't want that.

4 Answers

0 votes
answered Dec 10, 2010 by james-bedford

UITextView is a subclass of UIScrollView, so you can prevent the view from scrolling by setting the property scrollEnabled to NO.

0 votes
answered Dec 10, 2010 by mark-mcdonald

Just set the UITextView’s content size to be less than or equal to its bounds, this will prevent scrolling and still accept touch events.

0 votes
answered Dec 25, 2010 by william-jockusch

If I set scrollEnabled to NO and have an empty implementation of scrollRectToVisible:animated:, it appears to disable scrolling.

0 votes
answered Sep 15, 2017 by victor-camargo

Swift 3

let textView = UITextView()
textView.isScrollEnabled = false
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter