首页 > 解决方案 > 如何在 SwiftUI 中将图片添加到 iPad 导航视图的一侧?

问题描述

我有一个 TabBar 视图,它有一个导航视图作为选项卡之一。在 iPad 上,视图拥抱左侧,我想要在右侧旁边的图片/徽标(如图所示)。我将如何添加这个?

在此处输入图像描述

这是我的导航视图代码:

struct StartGameScreen: View {
    
    @ObservedObject var processor = EventsProcessor.shared
    
    @State var showGame = false
    
    var body: some View {
        NavigationView{
            Form{
                Section(header: Text("Teams")){
                    TextField("Home Team Name", text: $homeName)
                    TextField("Away Team Name", text: $awayName)
                }
                Section(header: Text("The Fixture")){
                    TextField("Location", text: $location)
                    DatePicker("Date of Fixture", selection: $date, displayedComponents: .date)
                }
                Section(header: Text("Officials")){
                    TextField("Referee", text: $referee)
                    TextField("Assistant Referee 1", text: $ar1)
                    TextField("Assistant Referee 1", text: $ar2)
                    TextField("4th Official", text: $fourthOfficial)
                    TextField("Televsion Match Official", text: $tmo)
                    
                }
                
                Button("Start Game"){
           
                    self.showGame.toggle()
                    
                }
                .fullScreenCover(isPresented: $showGame, content: {
                    ContentView()
                })
                
            }
            .navigationBarTitle("New Game")
            
        }
        
    }
}

标签: swiftui

解决方案


你可以添加它

var body: some View {
    NavigationView{
        Form{
           // ... other code                
        }
        .navigationBarTitle("New Game")
        
        Image("logo")          // << here !!
    }
}

推荐阅读