【发布时间】:2022-08-04 06:26:42
【问题描述】:
iPhone 视图正是我想要的方式,但 iPad 视图呈现怪异。如果你看这两个图像,iPad 版本就像一个侧边栏视图。我不确定为什么。任何帮助表示赞赏!我正在尝试制作像 iPhone 一样的 iPad 版本。我在设置时确实选择了应用程序选项,并选择了 iOS 作为部署。检查目标时,它会显示“iPhone、iPad”。
另外,如何将标签栏编辑为不同的颜色,将 SF 符号编辑为不同的颜色?我在想也许是因为它在标签中不能修改?
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)可能不同,因此请使用任一显式样式(不推荐)并为每个平台采用原生外观。