SwiftUI Navigation Title Text Priority (of two texts)

720 Views Asked by At

I have two texts that I would like to display in a navigation title:

...
        .navigationTitle(Text(getTitle()) + Text(" (\(selection + 1)/\(sequenceObject.homeElements.count))"))

However, the first text could become too large after user input and the second text would no longer be displayed (

This is a verly long navigation ti...

). But the second text must always be visible!!! My wish text layout of the navigation title would be:

This is a very long...second text

Any ideas?

Best regards!

1

There are 1 best solutions below

1
On

You need to do it a little bit different. .navigationTitle is not made for a long title, but if you do need a long title, use the Text modifier like this:

NavigationView{
            VStack(){
                //"your Code
            }
            .navigationBarTitleDisplayMode(.large)
            .toolbar {
                ToolbarItem(placement: .navigationBarLeading) {
                    VStack {
                        Text("This is a very long title").font(.largeTitle).bold()
                        Text("with our subtitle").font(.subheadline)
                        //you can also do .font(.largeTitle).bold() here
                    }
                }
            }
        }