当前页面的 UIPageControl 点大小

UIPageControl Dot Size for current page

我正在尝试找出如何使所选页面的点比其他页面稍大,如下所示:

第 1 页:

第 2 页:

我可以更改所有点的点颜色、大小、背景等,但不能更改特定点当前页面的。
如何仅更改当前页面的点大小?

这可以是 Swift 或 Objective-C。

默认的 UIPageControl 实现不允许您更改点的外观。 幸运的是,有很多开源替代品,例如:

您可以浏览 Github search 以找到最适合您的需求。

Swift

func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
    
    let x = targetContentOffset.pointee.x
    
    pageControl.currentPage = Int(x / self.frame.width)
    
    
    // on each dot, call the transform of scale 1 to restore the scale of previously selected dot
    
    pageControl.subviews.forEach {
        [=10=].transform = CGAffineTransform(scaleX: 1, y: 1)
    }
    
    // transform the scale of the current subview dot, adjust the scale as required, but bigger the scale value, the downward the dots goes from its centre.
    // You can adjust the centre anchor of the selected dot to keep it in place approximately.
    
    let centreBeforeScaling = self.pageControl.subviews[self.pageControl.currentPage].center
    
    self.pageControl.subviews[self.pageControl.currentPage].transform = CGAffineTransform(scaleX: 1.5, y: 1.5)
    
    
    // Reposition using autolayout
    
    self.pageControl.subviews[self.pageControl.currentPage].translatesAutoresizingMaskIntoConstraints = false
    
    self.pageControl.subviews[self.pageControl.currentPage].centerYAnchor.constraint(equalTo: self.pageControl.subviews[0].centerYAnchor , constant: 0)
    
    self.pageControl.subviews[self.pageControl.currentPage].centerXAnchor.constraint(equalTo: self.pageControl.subviews[0].centerXAnchor , constant: 0)

    
//    self.pageControl.subviews[self.pageControl.currentPage].layer.anchorPoint = centreBeforeScaling
    
}