struct MostViewedViewItem: View {
let moviePic: String = "image_placeholder"
let movieName: String = "Movie Name Loading..."
var body: some View {
Button {
// TODO: add a navigation link to the movie
} label: {
ZStack(alignment: .bottom) {
Image(moviePic)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 170, height: 100)
.clipShape(RoundedRectangle(cornerRadius: 3))
.overlay(
Text(movieName)
.scaledToFill()
.frame(height: 30)
.foregroundColor(.white)
.background (
Rectangle()
.fill(Color("lighter_bg"))
.opacity(0.4)
),
alignment: .bottom
)
}
}
}
}
我试图在背景中添加填充,所以我希望背景填充整个水平空间,但我希望文本有一些填充,如何做到这一点?