I've been having a very hard time finding good examples of UIScrollView. Even Apple's UIScrollView Suite I find a bit lacking.
I'm looking for a tutorial or example set that shows me how to create something similar to the iPhone Safari tab scrolling, when you zoom out from one browser window and can flick to others.
But I'm having a hard time just getting any old view showing within a scroll view. I have a view set up with an image in it, but when I add it to the scroll view, I only get a black rectangle, no matter what I put in the view I add.
Any links or code snippets would be great!
UIScrollView is one of the most versatile and useful controls in iOS, and has been around since iOS 2.0. It's the basis for the very popular UITableView and it's a great way to present content that's larger to fit in a single screen view.
Discussion. This property specifies how the safe area insets are used to modify the content area of the scroll view. The default value of this property is UIScrollView. ContentInsetAdjustmentBehavior. automatic .
Overview. UIScrollView is the superclass of several UIKit classes, including UITableView and UITextView . A scroll view is a view with an origin that's adjustable over the content view. It clips the content to its frame, which generally (but not necessarily) coincides with that of the app's main window.
Here is a scroll view guide from Apple
The basic steps are:
UIScrollView
and a content view you want to put inside (in your case a UIImageView
).As for the paging behavior, check out UIScrollView’s pagingEnabled
property. If you need to scroll by less than a whole page you’ll need to play tricks with clipsToBounds
, sort of the reverse of what is happening in this StackOverflow question.
UIScrollView *scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; NSInteger viewcount= 4; for (int i = 0; i <viewcount; i++) { CGFloat y = i * self.view.frame.size.height; UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, y,self.view.frame.size.width, self .view.frame.size.height)]; view.backgroundColor = [UIColor greenColor]; [scrollview addSubview:view]; [view release]; } scrollview.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height *viewcount);
For more information Create UIScrollView programmatically
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With