Вот пример:
Код: Выделить всё
struct ImagedScrollView: View {
@State private var currentIndex: Int? = 0
var body: some View {
GeometryReader { geoProxy in
let size = geoProxy.size
ScrollViewReader { scrollProxy in
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack {
ForEach(0...35, id: \.self) { index in
let width = size.width-16
let height = size.height-16
ScrollView(.vertical, showsIndicators: false) {
VStack {
ForEach(1...100, id:\.self) { _ in
Text("Hello, World")
}
}
}
.frame(width: width, height: height)
.background(
Image(.pic1)
.resizable()
.scaledToFill()
.frame(width: width, height: height)
.clipShape(RoundedRectangle(cornerRadius: 25.0))
)
}
}
.scrollTargetLayout()
}
.scrollContentBackground(.hidden)
.scrollPosition(id: $currentIndex)
.scrollTargetBehavior(.viewAligned)
.padding(8)
}
}
}
}
Я пробовал изображение как в ZStack, так и в модификаторе фона.
Подробнее здесь: https://stackoverflow.com/questions/798 ... ckground-i
Мобильная версия