简体   繁体   中英

How to make for Pageviewcontroller background transparent

How to make for Pageviewcontroller background transparent, I am trying here to make it transparent

  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 {

试图使该控制器透明

添加pagecontrol之后

I've tested the following code and it works

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
        }
}

Plus all of the datasource and delegate required methods

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM