0

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.

enter image description here

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)
    }
}
Ufuk Köşker
  • 1,288
  • 8
  • 29
  • 1
    Federico Zantello just did a write up at [FiveStars.blog](https://www.fivestars.blog/articles/flexible-swiftui) that may help. He is trying to distribute subviews of different size in one container, so he has to compute where to cut them off and send to the next line. A similar mechanism should work for this. – Yrb Sep 21 '21 at 19:22
  • Thank you sir.. – Ufuk Köşker Sep 21 '21 at 19:35

0 Answers0