С любым прокладками изображение фактически выйдет из экрана, чем больше ландшафта, оно:
Вот мой код до сих пор:
Код: Выделить всё
import SwiftUI
struct Card: View {
private enum Constants {
static let height: CGFloat = 152
}
let backgroundImage: Image
let title: String
let subtitle: String
let iconBackgroundColor: Color
var body: some View {
ZStack {
backgroundImage
.resizable()
.scaledToFill()
.clipped()
VStack {
Spacer()
HStack(alignment: .bottom) {
VStack(alignment: .leading, spacing: 2) {
Text(title)
.font(.body)
.foregroundColor(.white)
Text(subtitle.uppercased())
.font(.caption)
.foregroundColor(.white)
}
Spacer()
Image(systemName: "heart")
.foregroundColor(.white)
.frame(width: 36, height: 36)
.background(iconBackgroundColor)
.clipShape(Circle())
}
}
.padding(16)
}
.frame(height: Constants.height)
.clipShape(RoundedRectangle(cornerRadius: 16))
}
}
#Preview {
VStack {
Card(
backgroundImage: Image(.landscapeImage),
title: "THE TITLE",
subtitle: "And this is the subtitle",
iconBackgroundColor: .red
)
}
.frame(maxWidth: .infinity, maxHeight: 300)
.padding(.horizontal, 180) //
Подробнее здесь: [url]https://stackoverflow.com/questions/79685355/vstack-padding-not-working-with-landscape-image[/url]