是否可以使用 SwiftUI 中的 NavigationView 替换 iPad 导航栏中的默认后退按钮和侧边栏图标?

问题描述

我正在尝试制作一个使用 SwiftUI 的 NavigationView 构建侧边菜单的 iOS 应用。 在 iPhone 上它运行良好,但在 iPad 上我无法摆脱侧边栏按钮和后退按钮文本和图标。我想用名为 line.horizontal.3

的三个水平线图标替换这些按钮

Landscape screenshot with side menu icon I'd like to replace with three lines icon

Portrait screenshot with back button (woth icon and text) I'd like to replace with three lines icon

我使用的代码如下:

import SwiftUI

struct ContentView_iPad: View {
    @State var showMenu: Bool = false
    
    
    var body: some View {
        NavigationView{
            MenuView()
            iPad_menu()
                .navigationBarTitle("Side Menu",displayMode: .inline)
                .navigationBarItems(leading:
                                        (Button(action: {
                                            withAnimation{
                                                self.showMenu.toggle()
                                            }
                                        }){
                                            Image(systemName: "line.horizontal.3").imageScale(.large)
                                        }
                                        ))
                .navigationViewStyle(StackNavigationViewStyle())
        }
        
    }
}

主视图:

import SwiftUI
    
struct iPad_menu: View {
        var body: some View {
            EmptyView()
                .background(Color.black)
        }
    }

菜单视图:

import SwiftUI

struct MenuView: View {
    var body: some View {
        vstack(alignment: .leading) {
                    HStack {
                        Image(systemName: "person")
                            .foregroundColor(.gray)
                            .imageScale(.large)
                        Text("Profile")
                            .foregroundColor(.gray)
                            .font(.headline)
                    }
                        .padding(.top,100)
                    HStack {
                        Image(systemName: "envelope")
                            .foregroundColor(.gray)
                            .imageScale(.large)
                        Text("Messages")
                            .foregroundColor(.gray)
                            .font(.headline)
                    }
                        .padding(.top,30)
                    HStack {
                        Image(systemName: "gear")
                            .foregroundColor(.gray)
                            .imageScale(.large)
                        Text("Settings")
                            .foregroundColor(.gray)
                            .font(.headline)
                    }
                        .padding(.top,30)
                }
        .padding()
                    .frame(maxWidth: .infinity,alignment: .leading)
                    .background(Color(red: 32/255,green: 32/255,blue: 32/255))
                    .edgesIgnoringSafeArea(.all)
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...