Way*_*eio 3 xcode ios swift swiftui
我正在尝试设置NavigationView. 我正在尝试ZStack使用下面的代码添加一个(部分来自 SwiftUI 教程)。然而它永远是白色的,除非我NavigationView...用Spacer()
var body: some View {
ZStack
{
NavigationView {
List {
Toggle(isOn: $userData.showFavoritesOnly) {
Text("Favourites")
}
ForEach(userData.landmarks) { landmark in
if !self.userData.showFavoritesOnly || landmark.isFavorite {
NavigationLink(destination: LandmarkDetail(landmark: landmark)) {
LandmarkRow(landmark: landmark)
}
}
}
}
.navigationBarTitle(Text("Landmarks"), displayMode: .large)
}
}.background(Color.blue.edgesIgnoringSafeArea(.all))
}
Run Code Online (Sandbox Code Playgroud)
我可以设置单个列表项的颜色,但我希望整个背景显示为蓝色
Moj*_*ini 12
它与UINavigationBar. 但是由于还没有直接的 api,您可以使用appearance以下方法更改它:
UINavigationBar.appearance().backgroundColor = .orange
UINavigationBar.appearance().tintColor = .green
UINavigationBar.appearance().barTintColor = .yellow
UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor.red]
UINavigationBar.appearance().largeTitleTextAttributes = [.foregroundColor: UIColor.red]
Run Code Online (Sandbox Code Playgroud)
你应该把它放在你确定编译器在init()方法内部读取的地方。
请注意,其中一些在 Xcode 11 beta 5 下将不起作用。
| 归档时间: |
|
| 查看次数: |
4858 次 |
| 最近记录: |