3

I'd like to change the ScrollBar offset when tapping on a TextField in a ScrollBar which is located at the bottom (so keyboard avoidance will trigger).

When I select a TextField, the ScrollBar adjusts. But the bottom part of the TextField (the gray background) is cut off. Is there a way to adjust this so that the whole TextField is visible?

enter image description here

Thanks for answering!

struct ContentView: View {
    
    var body: some View {
        VStack {
            ScrollView {
                ForEach(0..<20, id: \.self) { i in
                    TextField("Textfield \(i)", text: .constant(""))
                        .padding()
                        .background(Color.gray.opacity(0.2).cornerRadius(5))
                        .padding(.horizontal)
                }
            }
        }
    }
}

aheze
  • 24,434
  • 8
  • 68
  • 125
leonboe1
  • 1,004
  • 9
  • 27
  • did you find a solution to that ? as this is still happening in Swift UI 3 – JAHelia May 14 '22 at 11:54
  • 1
    You could integrate a UITextField in SwiftUI and add padding on top/bottom in the UIKit view. But I haven't found a solution which works for the regular TextField. – leonboe1 May 14 '22 at 13:50

0 Answers0