Hello Community!
I have a textfield like the one on the image below. I want the Textfield to be activated when the user taps on the white rounded rectangle or the text. Right now the tap has to be placed exactly on the text for it to do something. Setting a height for the textfield doesn’t seem to be helping.
One possible solution I have come up with, is using a text editor with a line limit of one instead and setting the frame to the one of the rectangle, but then the text is not centered.
Another solution could be using the new FocusState, but I see bug potential there.
Is there a better way of solving this?
What code are you using to achieve what you have in your picture? Please show your code so we can help you figure out a solution. There are ways to adjust the tap target but exactly how to do it depend on what your existing code looks like.
I added an “outer” ZStack with a background color so that the white rectangle in the “inner” ZStack that surrounds the TextField (which is confined by the .frame() modifier to 200 points high) stood out. I mean you could make the rectangle color whatever you like but you need to test it in light mode and dark mode to make sure that it looks OK.
Probably better to do something like this so that in either dark or light mode it works quite well. Not so sure that you need a rectangle to be 200 points high though.