无法更改 UIPageControl 中的 currentPage 属性

Posted

技术标签:

【中文标题】无法更改 UIPageControl 中的 currentPage 属性【英文标题】:Can not change currentPage property in UIPageControl 【发布时间】:2016-02-11 10:15:21 【问题描述】:
private func setupPageControl() 
    let appearance = UIPageControl.appearance()
    appearance.pageIndicatorTintColor = UIColor.grayColor()
    appearance.currentPageIndicatorTintColor = UIColor.whiteColor()
    appearance.backgroundColor = UIColor.darkGrayColor()
    appearance.currentPage = 2

我正在尝试更改 UIPageControl 在我的应用中的第一个位置,但我无法使用此代码获得适当的结果。

【问题讨论】:

currentPage 可以被访问为 pageControl.currentPage = pageControl 是 UIPageControl 出口的东西。 【参考方案1】:

您正在尝试通过外观代理设置currentPage,这显然不起作用,也不应该起作用。

以与页面控件属性/变量相同的方式设置属性以使其工作。

要知道哪些选择器应该与外观代理一起工作,请检查类的 Objective-C 头文件并查找 UI_APPEARANCE_SELECTOR 属性

【讨论】:

以上是关于无法更改 UIPageControl 中的 currentPage 属性的主要内容,如果未能解决你的问题,请参考以下文章