0

My view has this massive space above the title text and I was am not sure how to get rid of it as everything I've tried seems to do nothing. How can I remove this space? Initially, I intended to just hide the navigation bar, however, I want to the back button for demonstrative purposes.

Apologies for all the commented-out code.

How the view looks (the blue is just for visualization purposes):

enter image description here

Code for the above View:

struct LoggedinView: View {
    @Binding var userName:String
    @Binding var userModelData : UserModelData
    
    var userInformation : UserModel?
    
    var body: some View{
        NavigationView{
            VStack{
                if let items = userInformation{
                    /*Text("\(items.username)'s \(items.type)")
                        .font(.title)
                        .fontWeight(.bold/)*/
                    
      
                    List(items.items, id: \.self){ item in
                                Text(item)
                    }
                    .navigationTitle("\(items.username)'s \(items.type)")
                    //.navigationBarHidden(true)
                }

            }
            //.navigationTitle("Hi")
            //.navigationBarHidden(true)
            //.navigationBarTitleDisplayMode(.inline)
          
        }.onAppear {
            UINavigationBar.appearance().backgroundColor = .blue
        }
        //.navigationBarHidden(true)
        //.navigationTitle("")
     
    }
}

Code that displays the view shown:

struct ContentView: View {
    @State public var userName: String = ""
    @State public var userPassword: String = ""
    @State private var errorMsg: String = ""
    
    @State private var showPassword: Bool = false
    @State private var authenticationPassed:Bool = false
    
    @State var userModelData = UserModelData()

    var userInformation : UserModel? {
            userModelData.userInformation.first { $0.username == userName }
        }
    
    @State var errorMsgColor = Color(red:220.0/255.0, green:0.0, blue:0.0)

    var body: some View {
 
    NavigationView{
        VStack{
            Group{ //titles
                Text("Welcome Back!")
                    .fontWeight(.bold)
                    .font(.largeTitle)
                
                UserImage()
                
                Spacer()
                    .frame(height: 25)
            }
            
            Group{ //inputs
                TextField("Username", text: $userName )
                    .padding()
                    .overlay(RoundedRectangle(cornerRadius: 30.0)
                                        .stroke(Color.black, lineWidth: 3))
                    .disableAutocorrection(true)
                    .autocapitalization(.none)
                
                Spacer()
                    .frame(height: 20)
                
                if showPassword{

                    TextField("Password", text: $userPassword)
                        .padding()
                        .overlay(RoundedRectangle(cornerRadius: 30.0)
                                    .stroke(Color.black, lineWidth: 3))
                        .disableAutocorrection(true)
                        .autocapitalization(.none)
                }else{
                   
                    SecureField("Password", text: $userPassword)
                        .padding()
                        .overlay(RoundedRectangle(cornerRadius: 30.0)
                                .stroke(Color.black, lineWidth: 3))
                        .disableAutocorrection(true)
                        .autocapitalization(.none)
        
                }
                
                ShowPasswordButton(showPassword: $showPassword)
            }
            
            Group{ //error msg + button
                Button(action:{
                    
                    if self.userName == userInformation?.username && self.userPassword == userInformation?.password {
                        self.authenticationPassed = true
                    }else{
                        self.authenticationPassed = false
                    }
                    
                    if !authenticationPassed {
                        errorMsg = "Incorrect username or password, please try again"
                        errorMsgColor = Color(red:220.0/255.0, green:0.0, blue:0.0)
                    }else{
                        errorMsg = "Success"
                        errorMsgColor = Color(red:0.0, green:200.0/255.0, blue:0.0)
                    }
                
                }){
                    CustomButtonStyle(buttonText: "Login")
                }
                
                Spacer()
                    .frame(height: 25)
                
                Text(errorMsg)
                    .foregroundColor(errorMsgColor)
                
                NavigationLink(destination: LoggedinView(userName: $userName, userModelData: $userModelData, userInformation: userInformation), isActive: $authenticationPassed){
                    EmptyView()
               }
                //.navigationTitle("")
                .navigationBarHidden(true)
            }
            
        }
        .padding()
        //.navigationTitle("")
        .navigationBarHidden(true)
    }
        
    }
}
CartoonyAli
  • 45
  • 1
  • 6

0 Answers0