当前页面的UIPageControl点大小

时间:2018-07-12 10:49:27

标签: ios uikit uipagecontrol

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

第1页:

UIPageControl's first dot is bigger

第2页:

UIPageControl's second dot is bigger

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

这可以是Swift或Objective-C。

2 个答案:

答案 0 :(得分:3)

迅速

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 {
        $0.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

}

答案 1 :(得分:-2)

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

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