Reputation: 25
I have implemented a paging UIScrollView
following this excellent tutorial:
http://www.iosdevnotes.com/2011/03/uiscrollview-paging/
The UIScrollView
works like a charm with paging and all. Now, I want to add a UITextView
to each of the pages. The TextView
should have a fixed size to fit the frame but with scrolling content (if needed). I'm banging my head against the wall because no matter what I try I can't get the textview to scroll! In the main for-loop from the above tutorial I added the following code:
CGRect labelFrame;
UITextView *textView;
labelFrame.size.width = scrollView.frame.size.width-24;
labelFrame.size.height = scrollView.frame.size.height-48;
labelFrame.origin.x = 10;
labelFrame.origin.y = 40;
textView = [[UITextView alloc] initWithFrame:labelFrame];
textView.textColor = [UIColor blackColor];
textView.backgroundColor = [UIColor redColor];
textView.font = [UIFont systemFontOfSize:13];
textView.text = @"a very long text";
textView.editable = NO;
textView.scrollEnabled = YES;
textView.userInteractionEnabled = YES;
textView.delegate = self;
textView.contentSize = CGSizeMake(1, 1000); //this would make it scroll?
[subview addSubview:textView];
I've googled and tested a lot of things but the textview won't scroll. I tested the delaysContentTouches
flag, I've locked scrolling directions but it does not change a thing.
In another project I tried to do the same and there I got it to scroll on the first page but not on the others?
I'm totally lost in space right, hope that anyone out there have the (probably simple) solution.
Here is a link to the complete project:
https://dl.dropbox.com/u/7312515/mycode.zip
Upvotes: 1
Views: 1727
Reputation: 80273
I just tested this and it works fine.
In your code, you are adding the text view to the subview
. Instead, you should be adding it to the scroll view.
The subview does nothing, just provide the red color. You can send it to the back by calling
[self.scrollView bringSubviewToFront:textView];
PS: Don't forget to adjust the x
of labelFrame
to subview.frame.size.width +10
. ;-)
Upvotes: 1