ios - 当前页面的 UIPageControl 点大小

标签 ios uikit uipagecontrol

<分区>

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

第 1 页:

UIPageControl's first dot is bigger

第 2 页:

UIPageControl's second dot is bigger

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

这可以是 Swift 或 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
    
}

关于ios - 当前页面的 UIPageControl 点大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51303719/

相关文章:

php - 将照片从 iOS 上传到服务器时出错

ios - TabBarItems 并设置它们的图像大小?

ios - (非原子、强)属性的生命周期在 iOS 中如何运作?

swift - 以编程方式创建的 UIPopoverPresentationController 填充屏幕

ios - 在 UIView 上设置多个边框

ios - 如何使用 ScrollView 和 pageController 显示图像和信息

ios - Storyboard中带有 PageControl 的 ScrollView

ios - NSSet 中的第一个实体具有较短的 ID,并且不保留值更改

iphone - CGContextClipToMask 不剪裁

ios - 像 App store 一样的水平滚动控件