0

I'm using xcode 9.1 and swift 4. I have 2 Buttons in my View Controller, and i want their colors changed when my carousel page is changed. Here's my code but it. I want it to check every time my carousel Scrolls. is there any "OnPageControl" Methods in swift 4?

Here's my code ( in viewDidLoad ) :

 if (self.carousel.pageControl.currentPage == 0) { self.registerButton.layer.borderColor = UIColor(red:68/255.0, green:180/255.0, blue:194/255.0, alpha: 1.0).cgColor self.loginButton.layer.backgroundColor = UIColor(red:68/255.0, green:180/255.0, blue:194/255.0, alpha: 1.0).cgColor NSLog("1") } else if (self.carousel.pageControl.currentPage == 1) { self.registerButton.layer.borderColor = UIColor(red:139/255.0, green:21/255.0, blue:21/255.0, alpha: 1.0).cgColor self.loginButton.layer.backgroundColor = UIColor(red:139/255.0, green:21/255.0, blue:21/255.0, alpha: 1.0).cgColor NSLog("2") } else if (self.carousel.pageControl.currentPage == 2) { self.registerButton.layer.borderColor = UIColor(red:174/255.0, green:135/255.0, blue:46/255.0, alpha: 1.0).cgColor self.loginButton.layer.backgroundColor = UIColor(red:174/255.0, green:135/255.0, blue:46/255.0, alpha: 1.0).cgColor NSLog("3") } 
1
  • Is your carousel subclass of UIPageViewController? Commented Nov 16, 2017 at 15:06

1 Answer 1

1

There is nothing like a UIPageControlDelegate but UIScrollViewDelegate offers scrollViewDidScroll for that purpose. Using scrollView.contentOffset.x you can get the current page, assign it to the pageControl.currentPage and update your buttons there.

Sign up to request clarification or add additional context in comments.

Comments