gpt4 book ai didi

swift - PageViewController透明或没有背景

转载 作者:可可西里 更新时间:2023-10-31 23:46:19 24 4
gpt4 key购买 nike

我对页面视图控制器的点指示器有问题。实际上是有背景的。我试过uicolor.clear,但没用。背景仍然是白色。我可以改变颜色,但我不知道如何去除它或使它透明。
找不到使其透明的方法。
附截图。
如何使背景色透明或去除?
视图控制器.swift

import Foundation
import UIKit

class ViewController: UIViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate {

// Hide status bar.
override var prefersStatusBarHidden : Bool {
return true
}

var pageViewController: UIPageViewController!
let pages = ["DomesticPageViewController", "SafariPageViewController", "ForestPageViewController"]

// Page View Controller Datasource

func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {

if let index = pages.index(of: viewController.restorationIdentifier!) {
if index > 0 {
return viewControllerAtIndex(index - 1)
}
}

return nil
}

func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {

if let index = pages.index(of: viewController.restorationIdentifier!) {
if index < pages.count - 1 {
return viewControllerAtIndex(index + 1)
}
}

return nil
}


func viewControllerAtIndex(_ index: Int) -> UIViewController? {
let vc = storyboard?.instantiateViewController(withIdentifier: pages[index])
return vc

}



override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

if let vc = storyboard?.instantiateViewController(withIdentifier: "MyPageViewController") {
self.addChildViewController(vc)
self.view.addSubview(vc.view)

pageViewController = vc as! UIPageViewController
pageViewController.dataSource = self
pageViewController.delegate = self

pageViewController.setViewControllers([viewControllerAtIndex(0)!], direction: .forward, animated: true, completion: nil)
pageViewController.didMove(toParentViewController: self)


}

}

private func setupPageControl() {
let appearance = UIPageControl.appearance()
appearance.pageIndicatorTintColor = UIColor.lightGray
appearance.currentPageIndicatorTintColor = UIColor.black
appearance.backgroundColor = UIColor.clear


}

func presentationCount(for pageViewController: UIPageViewController) -> Int {
setupPageControl()
return self.pages.count
}

func presentationIndex(for pageViewController: UIPageViewController) -> Int {
return 0
}


override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

}

家庭视图控制器.swift
import Foundation
import UIKit

class DomesticPageViewController: UIViewController {


override func viewDidLoad() {
super.viewDidLoad()

let backgroundImage = UIImageView(frame: UIScreen.main.bounds)
backgroundImage.image = UIImage(named: "domestic_bg1")
backgroundImage.contentMode = UIViewContentMode.scaleAspectFill
self.view.insertSubview(backgroundImage, at: 0)

}


override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()

}

}

最佳答案

如果使用的是页面控件:
使用故事板:
您可以使用故事板简单地设置色调颜色、当前页面颜色和背景颜色。参考下图
enter image description here
或以编程方式:

    pageControl.backgroundColor = UIColor.clear
pageControl.currentPageIndicatorTintColor = UIColor.black
pageControl.pageIndicatorTintColor = UIColor.white

关于swift - PageViewController透明或没有背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49581985/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com