开始学习swiftUI的开发。
为什么博客园的语言没有swift啊!
import SwiftUI struct MenuItem: Identifiable { var id = UUID() var function: String var description: String var imageName: String } let menuItems = [ MenuItem(function: "a", description: "a", imageName: "flower"), MenuItem(function: "a", description: "a", imageName: "a"), MenuItem(function: "a", description: "a", imageName: "a"), MenuItem(function: "a", description: "a", imageName: "a"), MenuItem(function: "a", description: "a", imageName: "a") ] struct ContentView: View { var body: some View { NavigationView{ List(menuItems) { menuItem in NavigationLink(destination: Image("flower")){ Image(systemName: "photo") VStack { Text(menuItem.function) Text(menuItem.description) } .font(.largeTitle) } } .navigationBarTitle(Text("Tang")) } } }
List遍历数组一开始不成功,发现是MenuItem结构没有实现Identifiable。还有一个小问题,在iPhone上导航栏正好占满屏幕,所以启动界面就是导航栏。而iPad是导航栏的返回界面。