swift 隐藏状态栏_ios - SwiftUI设置状态栏样式 - SO中文参考 - www.soinside.com

我一直试图在我的SwiftUI应用中将状态栏设置为浅色文本,因为它具有深色背景。

我在多个站点上找到了此解决方案,但无法使其正常工作。

HostingController.swiftimport Foundation

import UIKit

import SwiftUI

class HostingController : UIHostingController {

override var preferredStatusBarStyle: UIStatusBarStyle {

return .lightContent

}

}

这会在类声明行Reference to generic type 'UIHostingController' requires arguments in <...>上返回错误,建议修复为Insert '<>'。应用上述修复程序将导致错误Use of undeclared type ''

然后您将需要更改window.rootViewController文件中的SceneDelegate.swift。

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上引发了错误

有人知道吗?似乎很多麻烦只是设置状态栏颜色,我想这将是一个相当普遍的要求。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值