0

Okay So I'm having real trouble trying to get my pageControl to cooperate with my scroll. I tried different functions but I can seem to get it right. I'm able to call the right amount of views such as the white dots match the number of pictures I have but the dots don't move when I scroll from one picture to the other. How would you connect my pageControl to my scroll so when I scroll left and right it will respond the the pageControl?

// Number of views
                var numberOfViews = picSource.count    
                var picNum:CGFloat = CGFloat(picSource.count)
// Image Scroller
                let scroll = UIScrollView(frame:CGRectMake(-5, 650, screenWidth, 260))
                scroll.pagingEnabled = true
                scroll.showsHorizontalScrollIndicator = false
                scroll.showsVerticalScrollIndicator = false
                scroll.contentSize = CGSizeMake(picNum*screenWidth, 220)
                scroll.delegate = self

                let pageControl = UIPageControl(frame: CGRectMake(0, 600, 100, 25))
                pageControl.numberOfPages = numberOfViews
                pageControl.currentPage = 0
                pageControl.addTarget(self, action: "pageControlSwipe:", forControlEvents: UIControlEvents.ValueChanged)
                pageControl.backgroundColor = UIColor.redColor()
                pageControl.userInteractionEnabled = true
                self.view.bringSubviewToFront(pageControl)
                border.addSubview(pageControl)

// pageControl swipe
                func pageControlSwipe(sender: AnyObject) -> () {
                    let x = CGFloat(pageControl.currentPage) * scroll.frame.size.width
                    scroll.setContentOffset(CGPointMake(x, 0), animated: true) 
                }

                func scrollViewDidEndDecelerating(scroll: UIScrollView) -> () {
                    let pageNumber = round(scroll.contentOffset.x / (scroll.frame.size.width))
                    pageControl.currentPage = Int(pageNumber)
                }
Thomas Martinez
  • 1,631
  • 3
  • 16
  • 21

1 Answers1

0

To Connnect ScrolView With PageController See the link...
link here

in this have Main ScrollView -> PageController -> SubScrollView -> UIImageView -> UIImage

Community
  • 1
  • 1
ios developer
  • 198
  • 19