Post

Replies

Boosts

Views

Activity

Reply to How to move title from left to right
There are a couple of ways of doing it depending on what you want to do with the rest of the view. One way to do it would be to add a navigation bar title instead of a navigation title like this:   var body: some View {     NavigationView {       ZStack {         LinearGradient(gradient: /*@START_MENU_TOKEN@*/Gradient(colors: [Color.red, Color.blue])/*@END_MENU_TOKEN@*/, startPoint: /*@START_MENU_TOKEN@*/.leading/*@END_MENU_TOKEN@*/, endPoint: /*@START_MENU_TOKEN@*/.trailing/*@END_MENU_TOKEN@*/)       }       .navigationBarItems(trailing: Text("בית"))       .navigationBarTitle(Text(""), displayMode: .inline)       .edgesIgnoringSafeArea(.all)       .opacity(0.3)     }   } } or you can change the environment of the navigation view so that text on the left side will show on the right side like this:   var body: some View {     NavigationView {       ZStack {         LinearGradient(gradient: /*@START_MENU_TOKEN@*/Gradient(colors: [Color.red, Color.blue])/*@END_MENU_TOKEN@*/, startPoint: /*@START_MENU_TOKEN@*/.leading/*@END_MENU_TOKEN@*/, endPoint: /*@START_MENU_TOKEN@*/.trailing/*@END_MENU_TOKEN@*/)       }       .navigationTitle("בית")       .edgesIgnoringSafeArea(.all)       .opacity(0.3)     }.environment(\.layoutDirection, .rightToLeft)   } } This method will cause all mostly everything to start on the right side though. This may be good or bad depending on what else will be in the view. Hopefully one of these options will help.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’22
Reply to In SwiftUI how to ask user to save edits when dismissing a NavigationLink
Without any code I can't know for sure if this will work but I just tried this in my MacOS app, which has a detail view appear in a sheet modal, and it works. In my detail view I also have a button that calls a save function. To dismiss my detail view I have the following button: Button(action: { dismiss() }, label: { Text("Back") }) All I needed to do is add a call to my save function above "dismiss()" Button(action: { FileManager().saveText(infoText!) dismiss() }, label: { Text("Back") }) Now when I hit the button to dismiss my detail view my save function runs, which shows a save dialog, and when I hit the "Save" button in the dialog it saves the file and then the detail view closes. I hope this helps!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’22
Reply to Is there a way to Show Hide a sidebar with a button?
Hey, You can add the button to the toolbar window using the following code after a list. The toolbar item placement is set to ".automatic", which is what causes the button to appear in the sidebar toolbar like in Xcode. .toolbar { ToolbarItem(placement: .automatic) { Button(action: toggleSidebar, label: { Image(systemName: "sidebar.leading") }) } Then you need to add "toggleSidebar" function, which is:   #if os(iOS)   #else NSApp.sendAction(#selector(NSSplitViewController.toggleSidebar(_:)), to: nil, from: nil)   #endif } } All together you get something like this: var body: some View { List { NavigationLink(destination: ...) NavigationLink(destination: ...) NavigationLink(destination: ...) }.listStyle(SidebarListStyle()) .toolbar { ToolbarItem(placement: .automatic) { Button(action: toggleSidebar, label: { Image(systemName: "sidebar.leading") }) } }.navigationTitle("Search") } private func toggleSidebar() {   #if os(iOS)   #else NSApp.sendAction(#selector(NSSplitViewController.toggleSidebar(_:)), to: nil, from: nil)   #endif } } Don't mind the empty NavigationLinks in the list, they are just for example. The contents of the list do not really matter as long as the list works Hope this helps
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’22
Reply to ToolBar
The first thing that you need to do is construct the view properly including the main body. When you first create a new SwiftUI view file, it should look like this: import SwiftUI struct ContentView: View {     var body: some View {         Text("Hello, World!")     } } You can delete the "Text("Hello, World!")" if you do not need it and then you need to construct the view starting with something like a VStack, HStack, List, Table, etc.... Once that is done you can add the toolbar and your buttons. I have no idea how your data and ToDoItems are constructed so I am just guessing about how to import them and display them in a List but your code should look similar to this: import SwiftUI struct ContentView: View { let data: [Data] var body: some View { List(data id: \.self) { item in Text(item) } .toolbar { ToolbarItem(placement: .primaryAction) { Button(action: {                     data.data.append(TodoItem())                 }, label: {                     Image(systemName: "plus")                 }) } ToolbarItem(placement: .automatic) { Button("Filter") {} } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’22
Reply to Is there a way to Show Hide a sidebar with a button?
@MarkErbaugh Sorry for the late reply. Yes, you are correct that there is no native SwiftUI way to accomplish the task. As for a sidebar on the right side, there is a way to accomplish this but it is more complicated. I don't have any code right now that accomplishes it, but in the past I did something similar using a horizontal split view. It would appear and disappear depending on an @State var showRightSidebar = "false" and then I had a button that would toggle that variable to show and hid the view just like you would with a modal or sheet view.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’22
Reply to SwiftUI MacOS TableColumn compiler can't type-check expression in reasonable time.
I have run into this issue many times, so I feel your pain! Unfortunately the SwiftUI Table is garbage and the best way to get a table in SwiftUI is to use a NSTableView. I have gone through months of trial and error trying to figure out how to get additional columns and some other features such as movable columns, but it is just a waste of time. I now have an NSTableView that I created using InterfaceBuilder with its view controller wrapped in a NSViewControllerRepresentable and a Coordinator class and it works perfect. I used a NSArrayController with Cocoa Bindings which allowed me to set the table up in Interface Builder with very little code. All you have to do is change your data model, Long Call, into "@objc member class Long Call: NSObject {}" instead of a structure. If you have never used Interface Builder before it may look daunting, but it really isn't. Especially for just a NSTableView, it will save you a lot of time and frustration. There are a few tutorials and gitHub projects that you can find with a google search, as well as some good examples on this forum. If you get stuck let me know and I can help you. I hope this helps!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’22
Reply to Help with showing a spectrogram of an audio file
@MediaEngineer, Sorry for the late reply. I have been trying to upload an image showing my results but it won't let me. The image that I get is mostly yellow and orange dots. I don't really know why this is happening or what steps I should take to try and fix it, but I am sure my code incorrect. Have you been able to successfully create a spectrogram from an audio file before using Swift? Just curious. Thanks!
Topic: UI Frameworks SubTopic: AppKit Tags:
Oct ’22