Posts

Post not yet marked as solved
1 Replies
289 Views
I'm in the process of building a SwiftUI app with a Sidebar and Detail View. I've run into some issues and I need some help fixing them: When the app is launched, my detail view shows up at the right of the sidebar. Great! However, the button that is supposed to navigate to that view isn't highlighted, which could cause user confusion. How do I make this button "light up" (with that blue background indicating to the user that it is selected, highlighted) and make the code so that this view opens up when the app opens (like in other Apple apps, see Music and Files) When I click on one of my sidebar items (which are just NavigationLinks), the background doesn't turn blue (highlight) to indicate that item is selected. I feel like this would cause user confusion, and I'd like to figure out why my code doesn't do this. One side note and a useful piece of information: whenever I click the NavigationLink in the sidebar, the console prints this: onChange(of: UpdateTrigger) action tried to update multiple times per frame. In the macOS app, upon launch, the detail view shows up. Great. What doesn't show up is my sidebar with the options on it. How do I make it so that the sidebar shows up no matter what unless the user specifies to remove it from view? Attached are some images and my code. Thanks, y'all! struct ContentView: View {     var body: some View {                  // NavigationSplitView for the sidebar                  NavigationSplitView {                          // List of the options                          List {                                  // NavigationLink for my button                                  NavigationLink {                                          // Linking to my main view that I want to show up upon launch of the app                                          MainView()                                          // Label to make it look pretty                                      } label: {                     Label("Main View", systemImage: "icloud")                 }                                  // Make the sidebar actually look like a sidebar                                  .listStyle(.sidebar)                              }                          // NavigationTitle at the top of the sidebar                          .navigationTitle("Cling")                          //                      } detail: {                          // Make it so that the main screen shows up upon launch (however, this doesn't make the button light up to signify that the user has selected that view)                          MainView()         }     } }
Posted Last updated
.
Post not yet marked as solved
0 Replies
74 Views
This is a weird but simple issue that I'm having and I'm hoping someone can figure it out: I have a modal that contains a form and a NavigationView for the navigationTitle and navigationBarItems. However, the form doesn't take up the whole modal, leaving this weird white gap between the navigationBar and form. Is there any way to remove this weird gap? Attached is my code. Thanks!  var body: some View {         // Create Navigation View for the title at the top         NavigationView {             VStack(spacing: 0) {                                  Text("")                 // Navigation Title                                      .navigationTitle("Modal Title").navigationBarTitleDisplayMode(.inline)                 // Creating Cancel Button                     .navigationBarItems(leading: Button(action: {                         self.isPresented = false                     }, label: {                         Text("Cancel").frame(maxWidth: .infinity, alignment: .leading)                         .frame(alignment: .top)}))                 // Creating Add button                     .navigationBarItems(trailing: Button(action: {                         self.isPresented = false                         print("\(self.taskName)")                         print("\(self.description)")                     }, label: {                         Text("Add").frame(maxWidth: .infinity, alignment: .leading)                         .frame(alignment: .top)}))                 // Creating form for the text fields                 Form {                                          // Section 1: Title and Desctiption text views                     Section {                         TextField("Title", text: $taskName)                         TextField("Description", text: $description)                             .ignoresSafeArea()                                                                               }                                          Section {                                                  DatePicker("Date", selection: $date, in: Date()..., displayedComponents: .date)                             .datePickerStyle(GraphicalDatePickerStyle())                                                                                                   }                                                                   }                     }                                      }                              }
Posted Last updated
.
Post marked as solved
2 Replies
204 Views
I've created an HStack and am trying to make one of those titles that you find in Apple apps (Messages, Mail, etc.) at the top left. I've gotten the text to the right size, made it bold, and aligned to the left and used .frame(alignment: .top) to align it to the top, but for some reason it stays in the middle. What am I doing wrong? Below is the code and an image of the issue. import SwiftUI struct HomeScreen: View {     var body: some View {         HStack{             Text("Tasks").font(.largeTitle).fontWeight(.bold).frame(maxWidth: .infinity, alignment: .leading).padding()                 .frame(alignment: .top)                  }          } struct HomeScreen_Previews: PreviewProvider {     static var previews: some View {         HomeScreen()     } } } ![]("https://developer.apple.com/forums/content/attachment/9d21e948-cd73-404c-9b3c-02f7898c8cfe" "title=Screen Shot 2022-06-05 at 3.49.25 AM.png;width=704;height=1350")
Posted Last updated
.