Kenny Kurochkin
Kenny Kurochkin

Reputation: 1108

Change navigation title position from left to right

I'm trying to move a navigation title to right side instead of left, any idea on how to implement that?

init() {
    UINavigationBar.appearance().largeTitleTextAttributes = [.foregroundColor: UIColor.white]
}

var body: some View {
    NavigationView {
        Color.init("midnight blue")
            .edgesIgnoringSafeArea(.vertical)

            .navigationBarTitle("המרות מטבע")
            .navigationBarItems(trailing:
                Button(action: {
                    print("button pressed")

                }) {
                    Image(systemName: "plus")
                        .foregroundColor(Color.orange)
            })
    }
}

Upvotes: 0

Views: 1849

Answers (2)

JohnWick
JohnWick

Reputation: 261

you can use navigationBarItem where in you can customise your text. for me this code is working :

.navigationBarItems(trailing: Text("Title on Right"))
.navigationBarTitle(Text(""), displayMode: .inline)

check result here

Upvotes: 2

Marc T.
Marc T.

Reputation: 5320

I assume this is what you are looking for. But consider this is applied by iOS automatically dependend on your language settings.

NavigationView {
               Color.init("midnight blue")
                   .edgesIgnoringSafeArea(.vertical)

                   .navigationBarTitle("המרות מטבע")
                   .navigationBarItems(trailing:
                       Button(action: {
                           print("button pressed")

                       }) {
                           Image(systemName: "plus")
                               .foregroundColor(Color.orange)
                   })
         }.environment(\.layoutDirection, .rightToLeft)

Upvotes: 4

Related Questions