Disable Horizontal Scrolling to UITextView Programmatically

后端 未结 3 1129
迷失自我
迷失自我 2021-01-16 03:06

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

3条回答
  •  感情败类
    2021-01-16 03:37

    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.

提交回复
热议问题