TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: Hide navigationbar in navigationview not working

Forums > SwiftUI

Hello all,

I am struggling hiding the navigationbar on a navigationview. Navigationlink does work, but I want to remove the navigationbar on my Mainview. Here is my code:

//
//  ContentView.swift
//  Nuvora
//
//  Created by Pohl, Kay on 23.12.21.
//

import SwiftUI

//########################################################################
//Landing Page ###########################################################
//########################################################################
struct ContentView: View {

    var body: some View {
        NavigationView{
            ZStack{

                VStack(spacing: 0.0) {

                    Header() //Header View
                    Spacer ()
                    Main() //Main View
                    Spacer()
                    Spacer()
                    Bottom() //Bottom View

                }
            }

        }
        .navigationTitle("")
        .navigationBarHidden(true)

    }

}

//########################################################################
//Extensions #############################################################
//########################################################################
extension Color {
    init(_ hex: UInt, alpha: Double = 1) {
        self.init(
            .sRGB,
            red: Double((hex >> 16) & 0xFF) / 255,
            green: Double((hex >> 8) & 0xFF) / 255,
            blue: Double(hex & 0xFF) / 255,
            opacity: alpha
        )
    }
}

//########################################################################
//Previews ###############################################################
//########################################################################
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

//########################################################################
//Header View ############################################################
//########################################################################
struct Header: View {

    let pallette_mint =  Color(0x219EBC)
    var body: some View {

        VStack(alignment: .leading, spacing: 0) {
            HStack {
                Text("Nuvora")
                    .bold()
                    .foregroundColor(.white)
                    .font(.system(size:45))
                Spacer()
                NavigationLink(destination: Settings()){
                    Image(systemName: "gearshape.fill")
                        .resizable()
                        .frame(width: 28.0, height: 28.0)
                        .foregroundColor(.white)
                }
            }
            Text("Take care of your working time")
                .font(.subheadline)
                .fontWeight(.light)
                .bold()
                .foregroundColor(.black)
        }
        //.frame(maxWidth: .infinity, alignment: .leading)
        .padding()
        .background(pallette_mint)
        .shadow(radius: 20)

    }

}

//########################################################################
//Main View ##############################################################
//########################################################################
struct Main: View {

    let pallette_orange_light =  Color(0xFFB703)
    let palette_mint_light = Color(0x8ecae6)
    let palette_mint_dark = Color(0x023047)
    let palette_orange_dark = Color(0xfb8500)
    let pallette_mint =  Color(0x219EBC)

    var body: some View {

        //Configure Circle gradient
        let gradient = Gradient(colors: [palette_mint_light, pallette_mint])
        let linearGradient = LinearGradient(gradient: gradient, startPoint: .top, endPoint: .bottom)
        let style = StrokeStyle(lineWidth: 20,
                                lineCap: .round,
                                lineJoin: .round,
                                miterLimit: 1,
                                dash: [],
                                dashPhase: 0)
        //Circle and Time
        VStack {
            ZStack{
                Circle()
                    .stroke(Color.gray.opacity(0.08), style: StrokeStyle(lineWidth: 20, lineCap: .round))
                    .frame(width: 320, height: 320)
                Circle()
                    .trim(from: 0, to: 0.8 )
                    .stroke(linearGradient, style: style)
                    .rotationEffect(.degrees(-90))
                    .frame(width: 320, height: 320)
                    .animation(.easeInOut, value: 1)
                    .shadow(radius: 5)

                VStack {
                    Text("492")
                        .bold().font(.system(size: 80))
                        .foregroundColor(palette_mint_dark)
                        .padding(-19)
                    Text("minutes left")
                        .fontWeight(.light)
                    Text("Go Time: 15:02")
                        .fontWeight(.light)
                        .foregroundColor(.gray)
                        .padding(1)

                }

            }.padding(40)

            //Buttons
            HStack {
                //Play & Pause
                HStack(spacing: 20){

                    Image(systemName: "play.fill")
                        .foregroundColor(.white)

                    Text("Start")
                        .foregroundColor(.white)
                }
                .padding(.vertical)
                .frame(width: (UIScreen.main.bounds.width / 2) - 55)
                .background(pallette_orange_light)
                .clipShape(Capsule())
                .shadow(radius: 6)

                Spacer()

                //Restart
                HStack(spacing: 20){

                    Image(systemName: "arrow.clockwise")
                        .foregroundColor(pallette_orange_light)

                    Text("Restart")
                        .foregroundColor(pallette_orange_light)
                }
                .padding(.vertical)
                .frame(width: (UIScreen.main.bounds.width / 2) - 55)
                .background(

                    Capsule()
                        .stroke(pallette_orange_light, lineWidth: 2)
                )
                .shadow(radius: 6)

            }
            .padding(.horizontal, 40)
        }

    }

}

//########################################################################
//Bottom View ############################################################
//########################################################################
struct Bottom: View {
    var body: some View {
        let pallette_mint =  Color(0x219EBC)
        Text("Made with ")
            .foregroundColor(.secondary)
        + Text(Image(systemName: "heart.fill"))
            .foregroundColor(pallette_mint)
        + Text(" by myself")
            .foregroundColor(.secondary)
    }
}

I've put the header, main and bottom in subviews just to organize it a bit for me. I am a beginner and tried to find a solution in the internet without success. May I ask someone to help me here?

Thanks in advance Kay

2      

You need to attach the modifliers to the ZStack not the NavigationView

struct ContentView: View {

    var body: some View {
        NavigationView{
            ZStack{

                VStack(spacing: 0.0) {

                    Text("Header") //Header View
                    Spacer ()
                    Text("Main")//Main View
                    Spacer()
                    Spacer()
                    Text("Bottom") //Bottom View

                }
            }
            .navigationTitle("")
            .navigationBarHidden(true)
        }
    }
}

3      

@NigelGee Thanks for your fast help. It works now.

BR Kay

2      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.