UIPageControl - How to make the background transparent?

后端 未结 8 2680
無奈伤痛
無奈伤痛 2021-02-18 21:30

I am using UIPageControl and trying to make the background transparent.

UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageInd         


        
8条回答
  •  再見小時候
    2021-02-18 22:07

    I finally found a working solution for this problem in Swift. You can find the original code and answer in this link.

    It requires you to override the viewDidLayoutSubviews() function to bring the page control to the front of the view.

    override func viewDidLayoutSubviews() {
            super.viewDidLayoutSubviews()
    
            let subViews: NSArray = view.subviews
            var scrollView: UIScrollView? = nil
            var pageControl: UIPageControl? = nil
    
            for view in subViews {
                if view.isKindOfClass(UIScrollView) {
                    scrollView = view as? UIScrollView
                }
                else if view.isKindOfClass(UIPageControl) {
                    pageControl = view as? UIPageControl
                }
            }
    
            if (scrollView != nil && pageControl != nil) {
                scrollView?.frame = view.bounds
                view.bringSubviewToFront(pageControl!)
            }
        }
    

提交回复
热议问题