【问题标题】:Disable ipad SpiltView navigation禁用 ipad SpiltView 导航
【发布时间】:2022-08-04 06:26:42
【问题描述】:

iPhone 视图正是我想要的方式,但 iPad 视图呈现怪异。如果你看这两个图像,iPad 版本就像一个侧边栏视图。我不确定为什么。任何帮助表示赞赏!我正在尝试制作像 iPhone 一样的 iPad 版本。我在设置时确实选择了应用程序选项,并选择了 iOS 作为部署。检查目标时,它会显示“iPhone、iPad”。

另外,如何将标签栏编辑为不同的颜色,将 SF 符号编辑为不同的颜色?我在想也许是因为它在标签中不能修改?

ipad iphone


import SwiftUI



struct Home: View {
    var body: some View {
        
        TabView {
            NavigationView {
                ZStack{
                    Color.black
                        .edgesIgnoringSafeArea(.top)
                    Text(\"Logout\")
                    .foregroundColor(.white)
                }
                
            }
            .tabItem {
                Label(\"Logout\", systemImage: \"arrow.left.circle\")
            }
            
            NavigationView {
                ZStack{
                    Color.black
                        .edgesIgnoringSafeArea(.top)
                    Text(\"Home\")
                    .foregroundColor(.white)
                }

            }
            .tabItem {
                Label(\"Home\", systemImage: \"house.circle.fill\")
               
            }
            NavigationView {
                ZStack{
                    Color.black
                        .edgesIgnoringSafeArea(.top)
                    Text(\"Ship\")
                    .foregroundColor(.white)
                }
            }
            .tabItem {
                Label(\"Ship\", systemImage: \"shippingbox.circle.fill\")
            }
            NavigationView {
                ZStack{
                    Color.black
                        .edgesIgnoringSafeArea(.top)
                    Text(\"Add\")
                    .foregroundColor(.white)
                }
                }
            .tabItem {
                Label(\"Add\", systemImage: \"plus.circle.fill\")
            }
            NavigationView {
                ZStack{
                    Color.black
                        .edgesIgnoringSafeArea(.top)
                    Text(\"Order\")
                    .foregroundColor(.white)
                }
                
            }
            .tabItem{
                Label(\"Order\", systemImage: \"bag.circle.fill\")
            }
            NavigationView {
                ZStack{
                    Color.black
                        .edgesIgnoringSafeArea(.top)
                    Text(\"Reports\")
                    .foregroundColor(.white)
                }
                
            }
            .tabItem  {
                Label(\"Reports\", systemImage: \"doc.circle.fill\")
            }
            
        }
        
        }
        
        
    }

  • .navigationViewStyle(.stack)添加到您的 TabView 以修复 iPad。添加.accentColor(.orange) 更改图标颜色。
  • iPhone 和 iPad 设计不同,因此内置组件的默认样式(如NavigationView)可能不同,因此请使用任一显式样式(不推荐)并为每个平台采用原生外观。

标签: swift swiftui


【解决方案1】:

尝试将 .navigationViewStyle(StackNavigationViewStyle()) 添加到 tabView 它将使堆栈中的导航不使用侧边栏导航

import SwiftUI



struct Home: View {
var body: some View {
    
    TabView {
        NavigationView {
            ZStack{
                Color.black
                    .edgesIgnoringSafeArea(.top)
                Text("Logout")
                .foregroundColor(.white)
            }
            
        }
        .tabItem {
            Label("Logout", systemImage: "arrow.left.circle")
        }
        
        NavigationView {
            ZStack{
                Color.black
                    .edgesIgnoringSafeArea(.top)
                Text("Home")
                .foregroundColor(.white)
            }

        }
        .tabItem {
            Label("Home", systemImage: "house.circle.fill")
           
        }
        NavigationView {
            ZStack{
                Color.black
                    .edgesIgnoringSafeArea(.top)
                Text("Ship")
                .foregroundColor(.white)
            }
        }
        .tabItem {
            Label("Ship", systemImage: "shippingbox.circle.fill")
        }
        NavigationView {
            ZStack{
                Color.black
                    .edgesIgnoringSafeArea(.top)
                Text("Add")
                .foregroundColor(.white)
            }
            }
        .tabItem {
            Label("Add", systemImage: "plus.circle.fill")
        }
        NavigationView {
            ZStack{
                Color.black
                    .edgesIgnoringSafeArea(.top)
                Text("Order")
                .foregroundColor(.white)
            }
            
        }
        .tabItem{
            Label("Order", systemImage: "bag.circle.fill")
        }
        NavigationView {
            ZStack{
                Color.black
                    .edgesIgnoringSafeArea(.top)
                Text("Reports")
                .foregroundColor(.white)
            }
            
        }
        .tabItem  {
            Label("Reports", systemImage: "doc.circle.fill")
        }
        
    }.navigationViewStyle(StackNavigationViewStyle())
    
    }
    
    
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-09
    • 2015-07-17
    • 2012-03-10
    • 1970-01-01
    • 1970-01-01
    • 2011-01-24
    • 2023-03-29
    • 1970-01-01
    相关资源
    最近更新 更多