'SwiftUI Navigation Title Text Priority (of two texts)
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!
Solution 1:[1]
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
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mark Rotteveel |