M Faheem Rajput
M Faheem Rajput

Reputation: 778

How can I use UIScrollView?

How can I use UIScrollView? please give me a simple example with one scrolling image?

Upvotes: 7

Views: 32496

Answers (4)

Jeff John
Jeff John

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

Khomsan
Khomsan

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

Chetan Bhalara
Chetan Bhalara

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

Related Questions