如何使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 {
答案 0 :(得分:0)
我测试了以下代码并且可以正常使用
这是我的控制器类:
class PageViewController: UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate {
在那个课程中,我创建了这个变量:
lazy var pageArra: [UIViewController] = {
return[self.VCInstance("ONE"),self.VCInstance("TWO"),self.VCInstance("THREE"),self.VCInstance("FOUR")]
}()
使用此功能获取故事板资产。我给了4个ViewControllers上面列出的ID
private func VCInstance(_ name: String) -> UIViewController {
return UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: name)
}
这是我的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)
}
这就是我在加载时清除它的方法
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if view is UIScrollView {
view.frame = UIScreen.main.bounds
} else if view is UIPageControl {
view.backgroundColor = .clear
}
}
加上所有数据源和委托所需的方法