I have the same problem as described in navigationtitle too long in swiftui -- I want to scale down my navigation bar title to fit the available space. Here's the problem:
Here's my code, which incorporates the suggestion made in the answer to the other referenced question:
struct AboutView: View {
@Binding var showAboutView: Bool
var body: some View {
NavigationView {
Form {
Section() {
Text("A placeholder for information about this app.\n\nDetails forthcoming....")
}
if let url = URL(string: "mailto:sarjo@sarjosoftware.com?subject=My+Wonderful+App") {
Section() {
Link("Contact the Author", destination: url)
}
}
}
// *** suggested solution ***
.navigationTitle(Text("About My Wonderful App").minimumScaleFactor(0.5).lineLimit(1))
.navigationBarItems(trailing: Button(action: {
showAboutView = false
}) {
Text("Done").bold()
})
}
}
}
But this code fails to build with the error:
Instance method 'navigationTitle' requires that 'some View' conform to 'StringProtocol'
on the line Form {
.
If I move the modifiers on the title text outside to apply to the navigationTitle
modifier itself, as shown here:
.navigationTitle(Text("About My Wonderful App")).minimumScaleFactor(0.5).lineLimit(1)
this code builds and runs, but the modifiers are not applied to the title text but to the body text beginning "A placeholder for
:
Thanks for any suggestions.