【发布时间】:2019-09-29 09:07:15
【问题描述】:
我一直在尝试将 SwiftUI 应用程序中的状态栏设置为浅色文本,因为它有深色背景。
我在几个网站上找到了这个解决方案,但无法让它发挥作用。
HostingController.swift
import Foundation
import UIKit
import SwiftUI
class HostingController : UIHostingController {
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
}
这会在类声明行 Reference to generic type 'UIHostingController' requires arguments in <...> 上返回错误,并建议修复 Insert '<<#Content: View#>>'。应用上述修复会导致错误Use of undeclared type '<#Content: View#>'
然后您需要更改SceneDelegate.swift 文件中的window.rootViewController。
SceneDelegate.swift
...
// Create the SwiftUI view that provides the window contents.
let contentView = Login()
// Use a UIHostingController as window root view controller.
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = HostingController(rootView: contentView)
self.window = window
window.makeKeyAndVisible()
}
...
这会在window.rootViewController 行Argument passed to call that takes no arguments 上引发错误
有人有什么想法吗?设置状态栏颜色似乎很麻烦,我认为这是一个相当普遍的要求。
【问题讨论】:
标签: ios swift swiftui ios13 xcode11