Anonymous
VStack Padding не работает с изображением ландшафта
Сообщение
Anonymous » 01 июл 2025, 01:57
Я пытаюсь реализовать простой представление карты, и я могу изменить прокладку в предварительном просмотре с любым портретным изображением, но как только я использую любое ландшафтное изображение, прокладка больше не изменится. < /p>
Вот мой код: < /p>
Код: Выделить всё
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]
1751324254
Anonymous
Я пытаюсь реализовать простой представление карты, и я могу изменить прокладку в предварительном просмотре с любым портретным изображением, но как только я использую любое ландшафтное изображение, прокладка больше не изменится. < /p> Вот мой код: < /p> [code]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]