无法使我的状态栏颜色与SiwftUI中的UINavigationBar颜色匹配

问题描述

我的问题似乎很简单。但是我只是花了几个小时寻找解决方案! 我只需要使状态栏的背景色与我的UINavigationBar背景色(此示例中为红色)相符即可。

Status bar color is not conform to the NavigationBar's color

我写了一个最小的代码示例来重现我的问题,并帮助您为我提供解决方案...

TestApp.swift

import SwiftUI

@main
struct TestApp: App {
    @Environment(\.scenePhase) private var phase

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
        .onChange(of: phase) { newPhase in
            switch newPhase {
            case .active:
                UINavigationBar.appearance().backgroundColor = UIColor.red
                break
            default:
                break
            }
        }
    }
}

ContentView.swift

struct DetailView1: View {

    var body: some View {
        Text("Detail view 1")
    }
}

struct ContentView: View {
    @State private var isdisplayDetailView1 = true

    var body: some View {
        NavigationView {
            List {
                Section {
                    NavigationLink(destination: DetailView1(),isActive: $isdisplayDetailView1) {
                        Text("Go to detail view 1")
                    }
                }
            }
            .navigationBarTitle("Menu")
            .listStyle(GroupedListStyle())
        
            DetailView1()
        }
    }
}

很显然,我尝试将edgesIgnoringSafeArea(.top)添加到我的NavigationView视图(以及ListDetailView1视图中,...),但是什么都不会改变...请帮助我,我不知道问题出在哪里!

解决方法

您使用procedure TForm2.TCPClientStatus(ASender: TObject; const AStatus: TIdStatus; const AStatusText: string); var Client: TIdTCPClient; IO: TIdIOHandler; begin Client := nil; if ASender is TIdTCPClient then begin Client := TIdTCPClient(ASender); end else if ASender is TIdIOHandler then begin IO := TIdIOHandler(ASender); if IO.Owner is TIdTCPClient then Client := TIdTCPClient(IO.Owner); end; if Client <> nil then begin // use Client.Tag as needed... end; end;

是有原因的吗?

您只需在ScenePhase上添加此代码

file scope

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...