Reputation: 778
How can I use UIScrollView
? please give me a simple example with one scrolling image?
Upvotes: 7
Views: 32496
Reputation: 31
You can use below code to add UIScrollView on yourView :-
[self.ScrollView setContentSize:(CGSizeMake(self.view.frame.size.width, self.view.frame.size.height))];
Step:1 Create a UiScrollView,
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIScrollView *MyScrollView;
@end
Step2: In your ViewController.m,
[self.MyScrollView setContentSize:(CGSizeMake(self.view.frame.size.width, self.view.frame.size.height))];
Upvotes: 1
Reputation: 553
This can be one example. Basically we create a scrollview, set its frame, add content as a subview, and then set the content size. The image (iphone.png) below is bigger than the iphone screen so that we can scroll it.
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, 320, 460)];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iphone.png"]];
[scrollView addSubview:imageView];
[imageView release];
scrollView.contentSize = CGSizeMake(imageView.image.size.width, imageView.image.size.height);
[window addSubview:scrollView];
[scrollView release];
Upvotes: 5
Reputation: 8243
This will get you an insight of the UIScrollView
control:
Learning the basics of UIScrollView
Referenced from UIScrollView Tutorials
Some good samples with the basic functionalities covered
Not to mention:
Upvotes: 7
Reputation: 10344
Add UIImageView in to UIScrollView.
then,
Use
imageView.image = [UIImage imageNamed:@"image1.png"];
imageView.frame = CGRectMake(0.0, 0.0, imageView.image.size.width, imageView.image.size.height);
scrollView.contentSize = CGSizeMake(imageView.image.size.width, imageView.image.size.height);
Upvotes: 0