借助 SwiftUI,设计和实现复杂的 UI 已变得轻而易举。
ScrollView 当需要滚动功能时,开发人员通过添加子视图来使用设计屏幕。
import SwiftUI
struct Movie: Identifiable {
let id = UUID()
let title: String
let color: Color
static let dummyMovies: [Movie] = [
Movie(title: "a.square.fill", color: .red),
Movie(title: "b.circle", color: .green),
Movie(title: "c.square.fill", color: .blue),
Movie(title: "d.circle", color: .yellow),
Movie(title: "e.square.fill", color: .gray),
Movie(title: "f.circle", color: .purple),
]
}
struct ContentView: View {
var body: some View {
ScrollView {
ForEach(Movie.dummyMovies) { movie in
Image(systemName: movie.title)
.resizable()
.imageScale(.large)
.frame(height: 340)
.cornerRadius(16)