Spacing between navigationBarItems

216 Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER

Use different modifier, with leading and trailing parameters, like

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

Why you add two buttons in leading then you separate them ? you can use leading and trailing like this :

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