删除空格 NavigationTitle 但不删除后退按钮 [英] Remove space NavigationTitle but not the back button

查看:41
本文介绍了删除空格 NavigationTitle 但不删除后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不移除后退按钮的情况下移除 NavigationTitle Space.

I want to remove the NavigationTitle Space without removing the back button.

我已经试过了:

.navigationBarItems(trailing:
  NavigationLink(destination: Preferences(viewModel: viewModel).navigationBarHidden(true)) {
      Image(systemName: "gear")
          .font(.title2)
  }
)

但这也会删除后退按钮.

but that removes the back button as well.

推荐答案

标准Back按钮没有导航栏就不能显示,因为它是导航项,所以是导航栏的一部分.我假设您只需要透明的导航栏.

Standard Back button cannot be shown without navigation bar, because it is navigation item, so part of navigation bar. I assume you just need transparent navigation bar.

这是可能的解决方案的演示(使用 Xcode 12.1/iOS 14.1 测试)/图像用于更好的可见性/

Here is demo of possible solution (tested with Xcode 12.1 / iOS 14.1) / images are used for better visibility /

struct ContentView: View {
    
    init() {
        let navBarAppearance = UINavigationBarAppearance()
        navBarAppearance.configureWithTransparentBackground()
        UINavigationBar.appearance().standardAppearance = navBarAppearance
    }
    
    var body: some View {
        
        NavigationView {
            ZStack {
                Image("large_image")
                NavigationLink(destination: Image("large_image")) {
                    Text("Go to details ->")
                }
            }
            .navigationBarItems(trailing: Button(action: {}) {
                Image(systemName: "gear")
                    .font(.title2)
            }
            )
            .navigationBarTitle("", displayMode: .inline)
        }.accentColor(.red)
    }
}

这篇关于删除空格 NavigationTitle 但不删除后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆