I\'m looking for a way to disable horizontal scrolling of a UITextView programmatically, it was easy via the Interface Builder, but since I\'m designing the view programmati
With custom insets i found the best solution for me is to subclass the UITextView and then in the layoutSubviews call the following code.
-(void) layoutSubviews
{
// always keep content offset at x = 0
self.contentOffset = CGPointMake(0, self.contentOffset.y );
[super layoutSubviews];
}
Hope this helps someone.
Just to add a bit here, that "tiny bit of scrolling left and right" even after you disable horizontal scrolling is caused by the ContentInsets. The following disables that:
self.textView.contentInset = UIEdgeInsetsMake(5, 0, 5, 0);
This should help...
UITextView
is a subclass of UIScrollView
, so this is pretty easy to implement.
mytextView.contentSize = CGSizeMake(mytextView.frame.size.height,mytextView.contentSize.height);
mytextView.showsHorizontalScrollIndicator = NO;