gpt4 book ai didi

ios - swift 2 在不同的 View Controller 中应用相同的背景

转载 作者:行者123 更新时间:2023-11-29 00:53:50 26 4
gpt4 key购买 nike

我有 4 个以上的 Viewcontroller 都具有相同的类。当我在 Viewcontroller.swift 中添加背景时,它仅适用于一个 View Controller 。 `

class ViewController: UIViewController {`
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor(patternImage: UIImage(named: "bg")!)
}

我所有的 View Controller 都有不同的 Storyboard ID,所以也许我调用这些然后应用背景。我如何在我的所有 View Controller 上应用相同的背景而不保留它们。非常感谢任何建议。

最佳答案

在您的 AppDelegate 中,添加以下行:

window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Background.png"]]

然后在所有 View 中,只需设置:

self.view.backgroundColor = [UIColor clearColor]

关于ios - swift 2 在不同的 View Controller 中应用相同的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37819092/

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