Search code examples
iphoneobjective-cios5uipagecontrol

How to get the image in center of view using PageControl


I have 15 images in pagecontrol and I have 15 buttons in my application

Now if I press button 5 at that time image 5 from the page control should be in center of the screen.

if I press button 10 at that time image 10 from the page control should be in center of the screen.

How can I develop this kind of structure in my app?

share your ideas.

thanx in advance.


Solution

  • Try with this (assuming you're using a scrollview with paging enabled):

    -(IBAction)goToPage5:(id)sender{
        CGRect frame = self.scrollView.frame;
        frame.origin.x = frame.size.width * 5;
        //OR if you have set the tags to your buttons:
        //UIButton *b=(UIButton*)sender;
        //frame.origin.x = frame.size.width * b.tag;
        self.pageControl.currentPage=5;
        frame.origin.y = 0;
        [self.scrollView scrollRectToVisible:frame animated:YES];
     }