Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView - disable vertical scrolling

How can I disable vertical scrolling in my UITextView? I want it to basically just scroll horizontally.

like image 226
CodeGuy Avatar asked Nov 28 '22 18:11

CodeGuy


1 Answers

In some circumstances, when trying to clamp down on unwanted UITextView scrolling I have found it helpful to add something like the following to the UITextView delegate (this is a UIScrollView delegate method but, of course, UITextView inherits from UIScrollView). This might work for you.

- (void)scrollViewDidScroll:(id)scrollView
{
      CGPoint origin = [scrollView contentOffset]; 
      [scrollView setContentOffset:CGPointMake(origin.x, 0.0)];
}

What about the scrollEnabled property? Setting the scrollEnabled property to NO stops the user from scrolling (in both directions), but there are occasions where the system sends setContentOffset:animated: messages to a UITextView. The scrollEnabled property applies to both vertical and horizontal scrolling. Given your question, you might want to leave scrollEnabled as is.

like image 121
Obliquely Avatar answered Dec 09 '22 13:12

Obliquely