简体   繁体   中英

Disable horizontal scrolling in UITextView

Hello: I'm building an app that supports iOS 6 and higher. I have a few UITextView s throughout the app, and I noticed that on iOS 6, the text views are able to be scrolled horizontally. On iOS 7, they can only be scrolled vertically. Is there a way to restrict scrolling so that it will only scroll vertically?

I've checked out some other similar questions, but I don't want to add a UILabel to a UIScrollView .

Any help is much appreciated!

EDIT

When using the following two lines (per the answers suggested), this still doesn't work when setting content insets. Anyone know how to fix this?

Attempt to disable scroll:

tView.contentSize = CGSizeMake(tView.frame.size.width, tView.contentSize.height);
tView.showsHorizontalScrollIndicator = FALSE;

Insets:

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
      tView.contentInset = UIEdgeInsetsMake(kTextViewInsets, kTextViewInsets, kTextViewInsets, kTextViewInsets);
} else {
      tView.textContainerInset = UIEdgeInsetsMake(kTextViewInsets, kTextViewInsets, kTextViewInsets, kTextViewInsets);
}

I would subclass UITextView and override setContentOffset :

- (void)setContentOffset:(CGPoint)contentOffset
{
    super.contentOffset = CGPointMake(0.0, // Ignore the passed offset. Could also use self.contentOffset.x
                                      contentOffset.y);
}

Try this -

mytextView.contentSize = CGSizeMake(mytextView.frame.size.width,HEIGHT_YOU_WANT);

mytextView.showsHorizontalScrollIndicator = NO;

ALso take a look at SO Question may it help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM