【发布时间】:2021-06-05 19:27:48
【问题描述】:
我遇到了与navigationtitle too long in swiftui 中所述相同的问题——我想缩小导航栏标题以适应可用空间。问题来了:
这是我的代码,其中包含在对另一个引用问题的答案中提出的建议:
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()
})
}
}
}
但此代码无法构建并出现以下错误:
Instance method 'navigationTitle' requires that 'some View' conform to 'StringProtocol'在线Form {。
如果我将标题文本上的修饰符移到外面以应用于navigationTitle 修饰符本身,如下所示:
.navigationTitle(Text("About My Wonderful App")).minimumScaleFactor(0.5).lineLimit(1)
此代码构建并运行,但修饰符未应用于标题文本,而是应用于以 "A placeholder for 开头的正文文本:
感谢您的任何建议。
【问题讨论】:
标签: ios swiftui uinavigationbar