Here is the code from the swift file. I call it from the viewDidLoad function. I tried calling it from the viewDidAppear function also but the result is the same.
import UIKit
extension UIPageControl {
func customPageControl(dotFillColor:UIColor, dotBorderColor:UIColor, dotBorderWidth:CGFloat) {
for (pageIndex, dotView) in self.subviews.enumerated() {
if self.currentPage == pageIndex {
dotView.backgroundColor = dotFillColor
dotView.layer.cornerRadius = dotView.frame.size.height / 2
}else{
dotView.backgroundColor = .white
dotView.layer.cornerRadius = dotView.frame.size.height / 2
dotView.layer.borderColor = dotBorderColor.cgColor
dotView.layer.borderWidth = dotBorderWidth
}
}
}
}
class IntroSliderViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var slider: UIScrollView!
@IBOutlet weak var slideControl: UIPageControl!
let slide1 = [:]
let slide2 = [:]
let slide3 = [:]
var slides = [ DictionaryString,String ]()
override func viewDidLoad() {
super.viewDidLoad()
slides = [slide1,slide2,slide3]
slider.isPagingEnabled = true
slider.contentSize = CGSize(width: self.view.bounds.width * CGFloat(slides.count), height: self.view.bounds.height)
slider.showsHorizontalScrollIndicator = false
slider.delegate = self
slideControl.customPageControl(dotFillColor: UIColor(named: "Primary-Color")!, dotBorderColor: UIColor(named: "Primary-Color")!, dotBorderWidth: CGFloat(2))
loadSlides()
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let page = scrollView.contentOffset.x / scrollView.frame.size.width
slideControl.currentPage = Int(page)
}
func loadSlides() {
for (index,content) in slides.enumerated(){
if let slide = Bundle.main.loadNibNamed("sliderContent", owner: self, options: nil)?.first as? SliderContentView {
slide.backgroundImage.image = UIImage(named: content["background"]!)
slide.mainImage.image = UIImage(named: content["mainImage"]!)
slide.heading.text = content["heading"]
slide.textContent .text = content["textContent"]
slider.addSubview(slide)
slide.frame.size.width = self.view.bounds.size.width
slide.frame.size.height = self.view.bounds.size.height
slide.frame.origin.x = CGFloat(index) * self.view.bounds.size.width
}
}
}
}