admin管理员组文章数量:1296912
I want a view to have a navigation title, but I don't want the title to show on the screen; so that when I long press on the back button after showing a couple of views, I would see the title, not "Back"
I tried to add
.navigationTitle(movie.getMovieTitle())
.toolbar(.hidden, for: .navigationBar)
.navigationBarBackButtonHidden(false)
but it didn't work
I want a view to have a navigation title, but I don't want the title to show on the screen; so that when I long press on the back button after showing a couple of views, I would see the title, not "Back"
I tried to add
.navigationTitle(movie.getMovieTitle())
.toolbar(.hidden, for: .navigationBar)
.navigationBarBackButtonHidden(false)
but it didn't work
Share asked Feb 11 at 17:04 Mark GeeMark Gee 3491 gold badge2 silver badges11 bronze badges1 Answer
Reset to default 1If I understand correctly, the back button should be visible on nested screens, but the navigation titles should always be hidden.
One way to achieve this is to set the navigationBarTitleDisplayMode
to .inline
, then supply your own ToolbarItem
with placement .principal
. The item you supply takes the place of the default navigation title. The replacement can just be some dummy text that is hidden:
struct ContentView: View {
private var view1: some View {
VStack {
NavigationLink("Go to View 2") {
Text("View 2")
.navigationBarBackButtonHidden(false)
}
.navigationTitle("View 1")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .principal) {
Text("").hidden()
}
}
}
}
var body: some View {
NavigationStack {
VStack {
NavigationLink("Go to View 1") {
view1
}
}
.navigationTitle("Home")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .principal) {
Text("").hidden()
}
}
}
}
}
本文标签: iosHide navigation bar without losing its features Swift UIStack Overflow
版权声明:本文标题:ios - Hide navigation bar without losing its features Swift UI - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741645644a2390169.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论