ios - 如何使Pageviewcontroller背景透明

标签 ios swift uipageviewcontroller

如何使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 {

trying to making that controller as transparent

after adding pagecontrol

最佳答案

我测试了以下代码并且它有效

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/

相关文章:

ios - DetailViewController 上的 TabBar Controller

ios - 我需要自己释放添加到 NSDictionary 中的 NSNumbers 吗?

ios - 快速将 uiimageview 保存到 tableview?

ios - 来自 gpuimage lib 的 imageFromCurrentFramebuffer 保存黑帧

swift - 如何快速捕获按钮事件类型

ios - UIPageViewController 和 UIPageControl 透明背景色 - iOS

ios - 通过 Storyboard将 UIPageControl 添加到 UIPageViewController

ios - 移动 Swift iOS 应用程序以支持 Apple TV 作为新的 Target

ios - iOS 应用程序中的应用程序屏幕序列

ios - 自动布局中的 viewDidLayoutSubviews 在 UIPageViewController 上旋转