Krunal
Krunal

Reputation: 6490

Image inside Scrollview in iPhone

I am new to iPhone,

I want to do scrolling in my image which is inside scrollView but i am unable to scroll my image,

Here is my code snippet,

UIImage *image1 = [UIImage imageWithContentsOfFile:@"768bg_with_footer.gif"];
self.imageView = [[UIImageView alloc] initWithImage:image1];
[self.scrollView addSubview:self.imageView];
scrollView.contentSize = image1.size;
self.scrollView.contentOffset = CGPointZero;

I have taken ScrollView in my .xib file.

Any help will be appreciated.

Upvotes: 0

Views: 213

Answers (2)

atastrophic
atastrophic

Reputation: 3143

try following instead

self.scrollView.contentSize = self.imageView.frame.size;

Upvotes: 0

Tripti Kumar
Tripti Kumar

Reputation: 1581

Try this code:

UIImage *image1 = [UIImage imageNamed:@"768bg_with_footer.gif"];
self.imageView = [[UIImageView alloc] initWithImage:image1];
[self.scrollView addSubview:self.imageView];
scrollView.contentSize = image1.size;
self.scrollView.contentOffset = CGPointZero;

We use initWithContentsOfFile when we know the path of the image.Using it with imageName will give a null image.

Upvotes: 1

Related Questions