首先创建一个单独的动物Banner的卡片
struct AnimalCard: View {
var species: Species
var body: some View {
species.image()
.resizable()
.frame(height: 300)
.aspectRatio(1, contentMode: .fill)
.clipped()
.overlay(TextOverlay(species: species))
}
}
struct TextOverlay: View {
var species: Species
var gradient: LinearGradient {
LinearGradient(
gradient: Gradient(
colors: [Color.black.opacity(0.6), Color.black.opacity(0)]),
startPoint: .bottom,
endPoint: .center)
}
var body: some View {
ZStack(alignment: .bottomLeading) {
Rectangle().fill(gradient)
VStack(alignment: .leading) {
Text(species.name)
.font(.title)
.bold()
Text(species.description)
}
.padding()
}
.foregroundColor(.white)
}
}
其中TextOverlay是悬浮在上方的文本说明
创建PageView
struct PageView<Page: View>: View {
var viewControllers: [UIHostingController<Page>]
init(_ views: [