Reputation: 16957
I am using storyboard with auto layout, scene contains UITextView with some text in it, you can see in following image:
But whenever i move to this scene in running application, it would be like following:
I have researched it a lot and tried following code, even then it not worked for me:
[self.scrollView setContentOffset:CGPointZero animated:NO];
Any help would be appreciated.
Upvotes: 3
Views: 1623
Reputation: 1261
Here's what worked: just setting the UITextView's text property, then calling scrollRangeToVisible
with an NSRange with location:0, length:0. My text view was not editable, and I tested both selectable and non-selectable (neither setting affected the result).
Code:
[textview scrollRectToVisible:NSRange(0, 0) animated:YES];
Upvotes: 0
Reputation: 11567
contentTextView.scrollRangeToVisible(NSRange(location: 0, length: 0))
Upvotes: 1
Reputation: 5435
Try following, may it help:
[yourTextView scrollRectToVisible:CGRectMake(0,0,1,1) animated:YES];
OR
set the content offset in viewDidLayoutSubviews
for it to take effect.
- (void)viewDidLayoutSubviews {
[yourTextView setContentOffset:CGPointZero animated:NO];
}
OR
in viewDidLoad
[yourTextView scrollRangeToVisible:NSMakeRange(0, 1)];
Upvotes: 4