How to make a UIScrollView with a UITextView sub v

2019-08-29 05:47发布

问题:

I have a UIScrollView which has a subview UITextView. When I added text to UITextView by code, the view is scrolling to the last line. I want the view not to scroll when I add text to UITextView by code. Anyone can help me fix the problem?

回答1:

Finally I can fix my problem.

We just set YES the setScrollEnabled in UITextView before we change the text in UITextView and set NO after we change the text.

Here the example code

[yourTextView setScrollEnabled:YES];
yourTextView.text = [someString copy];
[yourTextView setScrollEnabled:NO];

:)