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

标签 ios background swift2 ios9 viewcontroller

我有 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/

相关文章:

ios - 用于用户身份验证的 Swift POST 或 GET 请求 iOS Swift

html - 背景图像不显示在 html css 中

java - 不知道如何设置背景图像

mvvm - 使用RxSwift测试ViewModel

ios - 在swift 2中从对象和键数组创建字典

ios - 如何从Objective-C中的UUID获取特性?

ios - PanoramaGL如何停止旋转

ios - +[iOS8 中的 JSQMessagesAvatarImageFactory 断言失败

ios - UIButton 背景图像调整大小

frameworks - Xcode 7.3 beta 1 与 Swift 中的 CommonCrypto