BLACK FRIDAY SALE: Save big on all my Swift books and bundles! >>

Increasing Textfield padding does not increase tappable area

Forums > SwiftUI

I just don't understand how something so simple is still so difficult to pull off in SwiftUI's current implementation. All I want is to create a textfield with an increased height and rounded corners. That part works. However tapping on the padding does not bring the textfield into focus. Also the padding is not respected in regards to the default keyboard avoidance in a scrollview. Do I really need to switch back to UIKit to pull this off? I just can't believe this hasn't been properly resolved at this point.

I've searched and I've searched and there isn't one decent solution to this problem. Some have people have come up with solutions to tappable area problem but the keyboard avoidance problem still persists. Has anyone been able to pull this off properly without resorting to UIKit??? I mean there no real way to increase the Textfield frame?? I just can't believe it.

   

Yep, I should have added some code. Sorry about that. Here's a sample to illustrate the issue. If you tap on the outside padding, you won't get focus. Also if you tap on the inside and do get focus, the keyboard should clip the blue padding as it doesn't take it into account when calculating the textfield height. Like I said, I haven't found any solution align that accounts for increasing the tappable area AND nicely handles keyboard avoidance. I'm currently switch to UIKit for my textfields until I do.

  ScrollView {
      VStack {
        Spacer()
          .frame(height: 600)

        TextField("", text: .constant(""))
          .padding(30)
          .background(RoundedRectangle(cornerRadius: 5).fill(.blue))
          .overlay(
            RoundedRectangle(cornerRadius: 4)
              .stroke(lineWidth: 1)
              .foregroundColor(.gray)
          )
          .foregroundColor(.black)
      }
    }

   

Hacking with Swift is sponsored by RevenueCat

SPONSORED In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.