当前页面的UIPageControl点大小 [英] UIPageControl Dot Size for current page

查看:379
本文介绍了当前页面的UIPageControl点大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to find out how to make the dot for the selected page be slightly bigger than the others as shown below:

第1页:

第2页:

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

I am able to change the dot color, size for all the dots, background, etc, but not for the specific dot of the current page.
How to change the dot size for the current page only?

这可以是Swift或Objective-C.

This can be Swift or Objective-C.

推荐答案

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 {
        $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
    
}

这篇关于当前页面的UIPageControl点大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆