如何使Pageviewcontroller背景透明, 我试图让它变得透明
super.viewDidLoad()
self.pageviewcontroller = self.storyboard?.instantiateViewController(withIdentifier: "PageViewController") as! UIPageViewController
self.pageviewcontroller.dataSource = self
self.pageviewcontroller.delegate = self
var pageControl = UIPageControl()
pageControl = UIPageControl.appearance()
pageControl.backgroundColor = .clear
pageControl.pageIndicatorTintColor = .gray
pageControl.currentPageIndicatorTintColor = UIColor(red: 0.00, green: 1.0, blue: 1.0, alpha: 1.0)
pageControl.backgroundColor = UIColor.clear
ViewControllers.append(
UIStoryboard(name: "Main", bundle: nil) .
instantiateViewController(withIdentifier: "DashboardViewController") as! BaseViewController)
ViewControllers.append(
UIStoryboard(name: "Main", bundle: nil) .
instantiateViewController(withIdentifier: "qwertyViewController") as! BaseViewController)
if let firstViewController = ViewControllers.first {
最佳答案
我测试了以下代码并且它有效
This is my controller class:
class PageViewController: UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate {
In that class I've created this variable:
lazy var pageArra: [UIViewController] = {
return[self.VCInstance("ONE"),self.VCInstance("TWO"),self.VCInstance("THREE"),self.VCInstance("FOUR")]
}()
Which uses this function to get the storyboard assets. I gave 4 ViewControllers the ID's listed above
private func VCInstance(_ name: String) -> UIViewController {
return UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: name)
}
This is my viewDidLoad:
override func viewDidLoad() {
super.viewDidLoad()
dataSource = self
delegate = self
var pageControl = UIPageControl()
pageControl = UIPageControl.appearance()
pageControl.pageIndicatorTintColor = .gray
pageControl.currentPageIndicatorTintColor = UIColor(red: 0.00, green: 1.0, blue: 1.0, alpha: 1.0)
}
And This is how I get it to clear when it loads
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if view is UIScrollView {
view.frame = UIScreen.main.bounds
} else if view is UIPageControl {
view.backgroundColor = .clear
}
}
加上所有数据源和委托(delegate)所需的方法
关于ios - 如何使Pageviewcontroller背景透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49450239/