Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImage Is Not Fitting In UIScrollView At Start

I have an image like:

Want To Have

When I load the image to uiimageview and then adding as a subview to uiscrollview, at start the image is showing like:

Dont Want To Have

The problem is I want to see all the image fit to screen at start but it is showing already zoomed. Is there a way to handle this please help ...

I have the code like:

[self.view addSubview:scrollView];
UIImageView *tempImageView = 
[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Tree.jpg"]];
self.imageView = tempImageView;
[tempImageView release];
[scrollView setContentMode:UIViewContentModeScaleAspectFit];
[imageView sizeToFit];
scrollView.backgroundColor=[UIColor blackColor];
scrollView.contentSize = imageView.frame.size;
scrollView.minimumZoomScale = scrollView.frame.size.width / imageView.frame.size.width;
scrollView.maximumZoomScale = 4.0;
[scrollView setZoomScale:1.0];
scrollView.clipsToBounds = YES;
scrollView.delegate = self;
[scrollView addSubview:imageView];
like image 785
aeciftci Avatar asked May 28 '11 12:05

aeciftci


1 Answers

Probably you are looking for this,

UIImageView *tempImageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Watson.jpg"]] autorelease];
tempImageView.frame = scrollView.bounds;
self.imageView = tempImageView;

scrollView.backgroundColor = [UIColor blackColor];
scrollView.minimumZoomScale = 1.0  ;
scrollView.maximumZoomScale = imageView.image.size.width / scrollView.frame.size.width;
scrollView.zoomScale = 1.0;
scrollView.delegate = self;

[scrollView addSubview:imageView];
like image 86
Deepak Danduprolu Avatar answered Nov 25 '22 05:11

Deepak Danduprolu