swiftswiftuinavigationbarspacingnavigationbaritems

Spacing between navigationBarItems


How can I separate two buttons located in .navigationBarItems so they appear in different corners of the screen like here:

enter image description here

Here's the code I'm using:

.navigationBarItems(leading:
    HStack {
        EditButton()
        Spacer()
        Button(action: {
                someAction()
            }) {
                Image(systemName: "plus")
            }
        }
)

Spacer() doesn't help here and those two buttons still go together.


Solution

  • Use different modifier, with leading and trailing parameters, like

    .navigationBarItems(
         leading: EditButton(), 
         trailing: 
            Button(action: {
                    someAction()
                }) {
                    Image(systemName: "plus")
                }
            })