1

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.

Philipp
  • 183
  • 1
  • 9

2 Answers2

2

Use different modifier, with leading and trailing parameters, like

.navigationBarItems(
     leading: EditButton(), 
     trailing: 
        Button(action: {
                someAction()
            }) {
                Image(systemName: "plus")
            }
        })
Asperi
  • 228,894
  • 20
  • 464
  • 690
1

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")
                                     }     
                             )