I have a TextField
with a fixed-size frame, but it still expands to wrap the entered text, even over siblings.
Initial state:
With some input:
Is there a way to prevent this in SwiftUI using TextField
or do I need to resort to ViewRepresentable?
My code for this layout looks something like:
HStack(spacing: 0) {
Text("1").fixedSize(horizontal: true, vertical: false).frame(width: 22)
TextField("Price", text: $text1).fixedSize(horizontal: true, vertical: false).frame(width: 70)
TextField("1", text: $text2).fixedSize(horizontal: true, vertical: false).frame(width: 30)
TextField("1", text: $text3).fixedSize(horizontal: true, vertical: false).frame(width: 70)
}.textFieldStyle(RoundedBorderTextFieldStyle())
Change order of modifiers, like
TextField("1", text: $text3)
.frame(width: 70) // << here !!
.fixedSize(horizontal: true, vertical: false)
Tested with Xcode 12.1 / iOS 14.1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With