简体   繁体   中英

Navigation bar title in Swiftui - iPhoneXR

The navigation bar title is working fine in iPhone 7 plus device but in iphoneXR, the navigation bar title is partially hidden.

iPhoneXR 中的 SwiftUI

Following is the code used to display this screen. LoginView and ResetView are defined in separate file

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)
    }
}

Isn't that because you have .edgesIgnoringSafeArea(.all) set so the content is flowing into the top safe area? I would try removing that.

Here is a simplified example based on you code snippet:

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)
    }
}

I added .edgesIgnoringSafeArea([.leading, .trailing, .bottom]) modifier to the inner NavigationView .

It looks like this on iPhone 11 (which has notch too):

在 iPhone 11 上预览

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM