我想在状态栏中显示对所有View Controller都可见的视图
示例:我需要在状态栏中显示“没有Internet连接”,并且在我们获得Internet连接后它会隐藏吗?
您可以将视图直接添加到状态栏:
// get the status bar
let statusBar = UIApplication.shared.value(forKey: "statusBarWindow") as? UIWindow
// create a subview & add it to the status bar
let subview = UIView(frame: CGRect(x: 20, y: 0, width: 20, height: 10))
subview.backgroundColor = .red
statusBar?.addSubview(subview)
statusBar?.bringSubview(toFront: subview)
Run Code Online (Sandbox Code Playgroud)
如果声明statusBar和noNetworkConnectionView,则可以从任何地方访问它以动态显示或隐藏它。
结果:
免责声明:我不确定Apple是否会批准以这种方式修改状态栏的应用程序。
| 归档时间: |
|
| 查看次数: |
723 次 |
| 最近记录: |