1、command + option + p 刷新canvas画布
2、SwiftUI支持环境:iOS13+Swift5.1+Xcode11
3、列表List使用:
struct ContentView: View {
var body: some View {
List(0 ..< 5) { item in
Image(systemName: "photo")
VStack(alignment: .center) {
Text("长城")
Text("北京")
.font(.subheadline)
.foregroundColor(.secondary)
}
}
}
}
4、SwiftUI导航栏,页面跳转:
struct ContentView: View {
var body: some View {
// 导航栏
NavigationView {
List(0 ..< 5) { item in
// 点击事件
NavigationLink(
destination: Text("好")) {
Image(systemName: "photo").cornerRadius(3.0)
VStack(alignment: .center) {
Text("长城")
Text("北京")
.font(.subheadline)
.foregroundColor(.secondary)
}
}
}.navigationTitle("世界地标")
}
}
}
5、页面跳转,页面叠加:
struct LandmarkDetail: View {
var body: some View {
// 叠加效果
ZStack(alignment: .bottomTrailing) {
Image("guide1")
.resizable()
.aspectRatio(contentMode: .fit)
.navigationBarTitle("试试", displayMode: .inline)
// 让文字靠最下显示
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
Text("北京呀~")
.font(.largeTitle)
.foregroundColor(.secondary)
}
}
}
struct LandmarkDetail_Previews: PreviewProvider {
static var previews: some View {
// 导航栏显示
NavigationView {
LandmarkDetail()
}
}
}
6、SwiftUI页面跳转正向传值:
网友评论