Question

I have to display images from the Photo Library using UIScrollview. Except the first image all the rest are not selected during runtime. To view them one has to scroll to the selected image. How do I view the image that I select instead of starting from the first image itself ? Thank you.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage *img = [info valueForKey: @"UIImagePickerControllerOriginalImage"];
[imagearray addObject:img];
[self dismissModalViewControllerAnimated:YES];
for (int i =0; i<[imagearray count]; i++) 
{ 
   CGFloat yOrigin = i * self.view.frame.size.width;
   image = [[UIImageView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
   [image setImage:[imagearray objectAtIndex:i]];
   [image setUserInteractionEnabled:YES];
   [scrollView1 addSubview:image];
   scrollView1.contentSize = CGSizeMake(self.view.frame.size.width * [imagearray count], 350.0);}
Was it helpful?

Solution

You should assign proper value to contentOffset property. Its the point from where scrollView will become visible. By default, it is at Origin. But you can set it at the point from where you want to display your scrollView.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top