UIPageControl out of the box does not allow to make active and inactive points of different sizes. What is the easiest / best way to do this? (full Swift solutions only)

enter image description here

    3 answers 3

    There is not a bad FXPageControle library. The only thing is that it is written in Objective C, it will have to be implemented through Bridge. Migration to Objective C.

    You can also create a UIView with an initializer of the number of pages in the form of a UIButton inside. Create for each page #selector and animate depending on the press. (This is a long process but more custom) Building a Custom Page Control .

    • Unfortunately, the library on objective-c is not an option) - xhr
    • Why Bridge at Apple is implemented very well)) - Victor Mishustin
    • I don't want to drag obj-c into a pure swift project - xhr

    Perhaps you will be satisfied with the following libraries (swift):

    ISPageControl

    SCPageControl

    FlexiblePageControl

      Used custom class inherited from UIPageControl. In it you need to specify two pictures that will be the active and inactive "point" of the pager. The rest is all the same, as with the usual UIPageControl, in the number and in the storyboard

       import UIKit class MELPageControl: UIPageControl { private let activeImage = UIImage(named: "paginatorDotGreen")! private let inactiveImage = UIImage(named: "paginatorDotGray")! // MARK: - @Overrides override var numberOfPages: Int { didSet { updateDots() } } override var currentPage: Int { didSet { updateDots() } } override func awakeFromNib() { super.awakeFromNib() pageIndicatorTintColor = UIColor.clear currentPageIndicatorTintColor = UIColor.clear clipsToBounds = false } // MARK: - Private Methods private func updateDots() { var i = 0 for view in self.subviews { if let imageView = imageForSubview(view) { if i == currentPage { imageView.image = activeImage } else { imageView.image = inactiveImage } i += 1 } else { var dotImage = inactiveImage if i == currentPage { dotImage = activeImage } view.clipsToBounds = false view.addSubview(UIImageView(image: dotImage)) i += 1 } } } private func imageForSubview(_ view: UIView) -> UIImageView? { var dot: UIImageView? if let dotImageView = view as? UIImageView { dot = dotImageView } else { for foundView in view.subviews { if let imageView = foundView as? UIImageView { dot = imageView break } } } return dot } } 

      If there is a simpler solution - share)