【发布时间】:2015-10-11 16:22:55
【问题描述】:
我在storyboard中使用了一个UIPageViewController,并写了一个继承自UIPageViewController的类。
我写完代码后发现页面指示器的背景颜色是黑色的,不知道怎么改。
我在网上搜索,发现很多人会使用 UIViewController+UIPageControl 来做自定义页面指示器。
是否可以在 UIPageViewController 中更改背景颜色?
谢谢!
【问题讨论】:
我在storyboard中使用了一个UIPageViewController,并写了一个继承自UIPageViewController的类。
我写完代码后发现页面指示器的背景颜色是黑色的,不知道怎么改。
我在网上搜索,发现很多人会使用 UIViewController+UIPageControl 来做自定义页面指示器。
是否可以在 UIPageViewController 中更改背景颜色?
谢谢!
【问题讨论】:
通过添加:
let pageControl = UIPageControl.init(frame: CGRectMake(0, UIScreen.mainScreen().bounds.size.height*14/15, UIScreen.mainScreen().bounds.size.width, UIScreen.mainScreen().bounds.size.height))
pageControl.backgroundColor = UIColor.init(red: 0, green: 147/255, blue: 229/255, alpha: 1)
view.addSubview(pageControl)
我已成功更改颜色。
但我还有一个问题。
虽然我已经将imageView设置为全屏,但是页面控件会覆盖图片的按钮,如何避免页面控件覆盖图片,只显示点?
【讨论】:
我为此苦苦挣扎了两个多小时。这是我在 Swift 4 中所做的
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
for view in self.view.subviews{
if view is UIPageControl{
(view as! UIPageControl).currentPageIndicatorTintColor = .yellow
}
}
}
在此块中拥有 UIPageControl 后,您应该能够自定义其指示器颜色
【讨论】: