Disable Horizontal Scrolling to UITextView Programmatically

微笑、不失礼 提交于 2019-12-01 14:33:41

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;

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);

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!