簡體   English   中英

Swiftui 中的導航欄標題 - iPhoneXR

[英]Navigation bar title in Swiftui - iPhoneXR

導航欄標題在 iPhone 7 plus 設備中運行良好,但在 iphoneXR 中,導航欄標題部分隱藏。

iPhoneXR 中的 SwiftUI

以下是用於顯示此屏幕的代碼。 LoginView 和 ResetView 在單獨的文件中定義

var body: some View {

    LoadingView(isShowing: .constant(self.isShowLoadingView)) {
        VStack
            {
                if(self.showLoginView)
                {
                    LoginView()
                }
                else if(self.showResetView)
                {
                    ResetView()
                }
                else
                {
                    NavigationView {
                        VStack(alignment: .leading)
                        {
                            Text(EMAIL).foregroundColor(Color.white)
                            TextField("", text: self.$emailid)
                                .foregroundColor(Color.black)
                                .padding(EdgeInsets(top: 0, leading: 0, bottom: 45, trailing: 0))
                                .textFieldStyle(RoundedBorderTextFieldStyle())

                            Text(PHONE_NUMBER).foregroundColor(Color.white)
                            TextField("", text: self.$phoneno)
                                .foregroundColor(Color.black)
                                .padding(EdgeInsets(top: 0, leading: 0, bottom: 45, trailing: 0))
                                .textFieldStyle(RoundedBorderTextFieldStyle())

                            Button(action: self.forgotPwdAction) {
                                HStack(alignment: .center) {
                                    Spacer()
                                    Text(OK_BTN).font(.headline).fontWeight(.bold).foregroundColor(Color.white).multilineTextAlignment(.center)
                                    Spacer()
                                }
                            }.padding().background(Color.green)

                            Spacer()
                        }.padding(40)
                            .background(Color.black)
                            .navigationBarTitle("Forgot Password")
                            .navigationBarItems(leading: self.btnBack)
                            .navigationBarHidden(false)
                    }
                }
        }
        .background(Color.black)
        .edgesIgnoringSafeArea(.all)
        .statusBar(hidden: true)
    }
}

這不是因為您設置了.edgesIgnoringSafeArea(.all)以便內容流入頂部安全區域嗎? 我會嘗試刪除它。

這是基於您的代碼片段的簡化示例:

struct ContentView: View {
    @State var haha = "placeholder"
    var body: some View {
        VStack
            {
            NavigationView {
                VStack(alignment: .leading)
                {
                    Text("EMAIL").foregroundColor(Color.white)
                    TextField("", text: self.$haha)
                        .foregroundColor(Color.black)
                        .padding(EdgeInsets(top: 0, leading: 0, bottom: 45, trailing: 0))
                        .textFieldStyle(RoundedBorderTextFieldStyle())
                    TextField("", text: self.$haha)
                        .foregroundColor(Color.black)
                        .padding(EdgeInsets(top: 0, leading: 0, bottom: 45, trailing: 0))
                        .textFieldStyle(RoundedBorderTextFieldStyle())
                    Spacer()
                }
                .padding(40)
                .background(Color.black)
                .navigationBarTitle("Forgot Password")
                .navigationBarHidden(false)
                .edgesIgnoringSafeArea([.leading, .trailing, .bottom])
            }
        }
        .background(Color.gray)
        .edgesIgnoringSafeArea(.all)
        .statusBar(hidden: true)
    }
}

我向內部NavigationView添加了.edgesIgnoringSafeArea([.leading, .trailing, .bottom])修飾符。

在 iPhone 11 上看起來是這樣的(它也有缺口):

在 iPhone 11 上預覽

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM