Search code examples
iphoneuiscrollviewuisliderzooming

Zoom scroll View with slide control


I want to zoom scroll view using slide control. In my scroll view i am adding image view.

So how can i use slider control for zooming??

Thanks in advance


Solution

  • I use this code in iPad to zoom-in and zoom-out of the Image. Set the slider minimum value to 1, maximum value to 3, and current value to 0.1.

    After that in value Changed of this slider just call bellow method.

    For Ex. see this code:

    - (void)viewDidLoad
    {
        UISlider *yourSlider = [[UISlider alloc]initWithFrame:CGRectMake(300, 100, 300, 23)];
        [yourSlider setMinimumValue:1];
        [yourSlider setMaximumValue:3];
        [yourSlider setValue:0.1];
    
       // Its zoom scroll view in 3x scale
        [yourSlider addTarget:self action:@selector(scaleOfImage:) forControlEvents:UIControlEventValueChanged];
    }
    

    and paste this bellow method in your .m file

    -(IBAction)scaleOfImage:(id)sender
    {
            // if you want to zoom UIImageView then use bellow code...and set slider value max 900 and min 100 
            //yourImageView.frame=CGRectMake(yourImageView.frame.origin.x, yourImageView.frame.origin.y, yourSlider.value,yourSlider.value);
            //[yourImage setCenter:CGPointMake(500, 400)];
    
             // if you want to zoom the scrollview then use this bellow code which in comment..
    
            [yourScrollView setZoomScale:yourSlider.value]; // here change the value of slider
    }