Reputation: 4103
i'm struggling to get UIScrollView working.
I have a UIScrollView with a UIImageView and UITextView as it's subviews.
The UIScrollView, UIImageView and UITextView are hooked up to my controller.
When I use this line of code in viewDidLoad:
self.scrollView.contentSize = CGSizeMake(320, 1000);
the scrolling works. However, when scrolling down, if the UITextView contains lots of text, the bottom part of the text is cut of.
I assume that I must adjust the frame of the UITextView. When I add these three lines in viewDidLoad:
CGRect frame = self.bioText.frame;
frame.size = self.bioText.contentSize;
self.bioText.frame = frame;
the text is cut off even more.
A few questions:
Upvotes: 1
Views: 703
Reputation: 3
Today I've just solved this problem. You can set the textView' frame in viewDidLayoutSubviews. This is the code in my App:
- (void)viewDidLayoutSubviews {
CGRect rect = self.textView.frame;
rect.size.height = self.textView.contentSize.height;
self.textView.frame = rect;
}
Hope this can help you.
Upvotes: 0
Reputation: 1098
You do not need to adjust the contentSize of the textView, it automatically adjusts according to its text
If you want to have the contentSize of your UIScrollView adjust according to its subviews and all of your subviews are vertically you can use this
CGFloat height = 0
for(UIView* sub in myScrollView.subviews)
height += sub.frame.size.height
myScrollView.contentSize = CGSizeMake(self.contentSize.width, height)
Upvotes: 1