SwiftUI – State change in UITextField causes the frameWidth to grow uncontrolled and ignore bounds/frame

You need to decrease priority of content resistance in makeUIView (so content would not push external layout set in SwiftUI) like below

func makeUIView(context: UIViewRepresentableContext<MyField>) -> UITextField {
    let field = UITextField(frame: .zero)
    field.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
    ...

Leave a Comment