Skip to content

Instantly share code, notes, and snippets.

@cpageler93
Created December 3, 2020 06:40
Show Gist options
  • Save cpageler93/7c1ab137130f0dc2960bf35993f5ed12 to your computer and use it in GitHub Desktop.
Save cpageler93/7c1ab137130f0dc2960bf35993f5ed12 to your computer and use it in GitHub Desktop.
.toolbar {
ToolbarItemGroup {
Button(action: {}, label: {
Image(systemName: "sidebar.left")
})
Spacer()
Button(action: {}, label: {
Image(systemName: "play.fill")
})
Button(action: {}, label: {
Image(systemName: "stop.fill")
})
}
}
@cpageler93
Copy link
Author

Looks like this:
Bildschirmfoto 2020-12-03 um 07 41 10

@tizba
Copy link

tizba commented Jul 6, 2021

Hi, on which view do you apply the .toolbar modifier so that the buttons are shown in the sidebar rather than next to "Untitled" ?
Thanks in advance.

@cpageler93
Copy link
Author

@tizba I unfortunately no longer have an executable app that contains the code. Those were my first steps with SwiftUI on macOS back then. I rewrote the whole app in AppKit, because SwiftUI was not that powerful as it is now.
In old git commits I found this code:

var body: some View {
     NavigationView {
         VStack {
             List {
                 Section(header: Text("Languages")) {
                     ForEach(document.languages) { language in
                         ...
                     }
                 }
             }
             ...
         }
         .listStyle(SidebarListStyle())
         .frame(minWidth: 220)
         .toolbar {
             ToolbarItemGroup {
                 Button(action: toggleSidebar, label: {
                     Image(systemName: "sidebar.left")
                 })

                 // Spacer()
                 // Button(action: {}, label: {
                 //     Text("Button")
                 // })
             }
         }
         EmptyView()
     }
 }

I can't promise you that the code still runs today and produces the right result. Good luck!

@tecspda
Copy link

tecspda commented Oct 27, 2021

unfortunately it only for lastest macos. ah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment