Post

Replies

Boosts

Views

Activity

embedded stacks
Afternoon All, Im trying to make a view that contains a view within it. Ie one button will take you to a given screen and produce a desired out put "path" , while the other button will take you into a loop with a given out put "Intensity" being either H,M,L. I want to keep the chevron back button at the top of the screen on all views but it only conforms to Path. below is an example of the code, I understand you can have two different stacks in the same view as the "parent / root will take priority" but don't know how to correct. import SwiftUI struct questionFour: View { @StateObject private var appData = AppData() init(){ UINavigationBar.setAnimationsEnabled(false) } var body: some View { NavigationView { EmptyBattery(appData: appData) } } } struct EmptyBattery : View { @ObservedObject var appData: AppData var body : some View { BatteryTButton(B1Color: .clear, B2Color: .clear, B3Color: .clear, appData: appData) } } struct RedBattery : View { @ObservedObject var appData: AppData var body : some View { BatteryTButton(B1Color: .clear, B2Color: .clear, B3Color: .red, appData: appData) } } struct OrangeBattery : View { @ObservedObject var appData: AppData var body : some View { BatteryTButton(B1Color: .clear, B2Color: .orange, B3Color: .orange, appData: appData) } } struct GreenBattery : View { @ObservedObject var appData: AppData var body: some View { BatteryTButton(B1Color: .green, B2Color: .green, B3Color:.green, appData: appData) } } struct questionFour_Previews: PreviewProvider { static var previews: some View { questionFour() } } struct BatteryTButton : View { var B1Color : Color var B2Color : Color var B3Color : Color @ObservedObject var appData: AppData @State private var isGreenBatteryActive = false @State private var isOrangeBatteryActive = false @State private var isRedBatteryActive = false var body: some View { ZStack { VStack(spacing: 15) { Text("Intensity?") .font(.largeTitle) Spacer() Image("EmptyBattery") Spacer() NavigationLink(value: 11) { Image("Tick") .resizable() .frame(width: 120,height:100) } } .navigationDestination(for: Int.self) { value in questionFive() } VStack(spacing: 15) { Button(action: { isGreenBatteryActive = true appData.intensity = "H" print("Your app intensity is:", appData.intensity) }) { Rectangle() .fill(B1Color) .frame(width: 200, height: 120) .cornerRadius(20) } .fullScreenCover(isPresented: $isGreenBatteryActive) { GreenBattery(appData: appData) //.navigationBarBackButtonHidden(true) } Button(action: { isOrangeBatteryActive = true appData.intensity = "M" print("Your app intensity is:", appData.intensity) }) { Rectangle() .fill(B2Color) .frame(width: 200, height: 120) .cornerRadius(20) } .fullScreenCover(isPresented: $isOrangeBatteryActive) { OrangeBattery(appData: appData) //.navigationBarBackButtonHidden(true) } Button(action: { isRedBatteryActive = true appData.intensity = "L" print("Your app intensity is:", appData.intensity) }) { Rectangle() .fill(B3Color) .frame(width: 200, height: 120) .cornerRadius(20) } .fullScreenCover(isPresented: $isRedBatteryActive) { RedBattery(appData: appData) //.navigationBarBackButtonHidden(true) } } .padding(.bottom, 30) } } }
1
0
287
Sep ’23
customized Navigation bar
Hello all, Im trying to add a back.chevron to the attached section of code above the navigationBartitle without the previous title included within the back button. any ideas ? Thankyou Connor import SwiftUI struct ContentView: View { init() { // Customize the UINavigationBar appearance let appearance = UINavigationBarAppearance() appearance.titleTextAttributes = [.font : UIFont.systemFont(ofSize: 35)] // Increase title font size //appearance.largeTitleTextAttributes = [.font : UIFont.systemFont(ofSize: 35)] // Increase large title font size UINavigationBar.appearance().standardAppearance = appearance } @EnvironmentObject var appData: AppData var body: some View { NavigationStack(path: $appData.path) { HStack { Spacer() // Push the title to the center VStack { NavigationLink(value: 1) { Circle() .frame(width: 100, height: 100) } NavigationLink(value: 2) { Circle() .frame(width: 100, height: 100) } NavigationLink(value: 3) { Circle() .frame(width: 100, height: 100) } } .navigationDestination(for: Int.self) { value in if value == 1 { TestView1() } else { Text("Selected box: \(value)") } } Spacer() // Push the content to the right } .navigationBarTitle("Todo Lists", displayMode: .inline) //this section updates "path as you click though the navigation,links" .onReceive(appData.$path) { CurrentSelectionCode in let path = CurrentSelectionCode print("your path is:", path) } } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }
2
0
447
Sep ’23
Output print statements
Hi all, I am unsure as to why my print statements aren't being shown in the output section when I run a simulation ? Please could you have a look at my code and explain ? import SwiftUI struct ContentView: View { @State var dateIdentifier : String = "" @State var lastSelectedIdentifier : String = "" var body: some View { NavigationView { VStack { Button(action: { dateIdentifier.append("a"); lastSelectedIdentifier.append("a"); print(dateIdentifier); }) { NavigationLink(destination: Text("OutPut")) { Rectangle() .frame(width: 100, height: 100) } } Button(action: { dateIdentifier.append("b"); lastSelectedIdentifier.append("b"); print(dateIdentifier); }) { NavigationLink(destination: Text("OutPut")) { Rectangle() .frame(width: 100, height: 100) } } Button(action: { dateIdentifier.append("c"); lastSelectedIdentifier.append("c"); print(dateIdentifier); }) { NavigationLink(destination: Text("OutPut")) { Rectangle() .frame(width: 100, height: 100) } } } } } } Thank you Connor
2
0
348
Aug ’23