Access the UIPageControl created by iOS6 UIPageViewController?

后端 未结 8 1039
盖世英雄少女心
盖世英雄少女心 2021-01-05 02:42

I\'m using a UIPageViewController with Navigation set to Horizontal, Transition Style set to Scroll (in InterfaceBuilder), and no spine. Which gives me a lovely

相关标签:
8条回答
  • 2021-01-05 03:12

    You can access this for all PageControl objects by using appearance (see the UIAppearance protocol), but to get a specific instance you'd have to use recursion. Swift code:

    let pageControl = UIPageControl.appearance()
    
    0 讨论(0)
  • 2021-01-05 03:12

    How about a nice, up to date Swift 1-liner?

    let pageControl = view.subviews.first { $0 is UIPageControl } as? UIPageControl
    

    Or if you like an extension:

    extension UIPageViewController {
        var pageControl: UIPageControl? {
            return view.subviews.first { $0 is UIPageControl } as? UIPageControl
        }
    }
    
    0 讨论(0)
提交回复
热议问题