Question: How can I detect the View overflowing the screen? For example, I want to write +1(+n) for the view that goes out of the screen.
TagList:
struct TagListView: View {
var tags = ["iPhone X", "iPhone 11", "iPhone 12", "iPhone 12 Pro Max"]
var body: some View {
VStack {
HStack {
ForEach(tags.indices, id: \.self) { index in
GeometryReader { geo in
TagCell(tag: tags[index])
.onAppear {
print("\(geo.frame(in: .global).maxX)")
}
}
}
}
}
}
}
TagCell:
struct TagCell: View {
var tag: String
var body: some View {
Text(tag)
.fixedSize()
.foregroundColor(.yellow)
.padding(8)
.background(Color.yellow.opacity(0.15))
.cornerRadius(15)
}
}