I’ve a problem with a customized UITextField wrapper in SwiftUI that is increasing to fill the complete display when coming into numbers. The textual content discipline ought to preserve its body dimension whereas cutting down the font dimension for longer numbers, however as an alternative, it is breaking its constraints.
Difficulty Particulars:
- When typing numbers, the textual content discipline expands past its meant body
- The textual content discipline ought to preserve its dimension and scale down the font for longer numbers
- Presently utilizing
adjustsFontSizeToFitWidth = true
but it surely’s not working as anticipated
Challenge Construction:
The problem is in DegenTrader/Views/Swap/SwapView.swift
, particularly within the CustomTextField
implementation:
struct CustomTextField: UIViewRepresentable {
// ... different properties
func makeUIView(context: Context) -> UITextField {
let textField = UITextField()
textField.adjustsFontSizeToFitWidth = true
textField.minimumFontSize = 16
// ... different configurations
}
}
The textual content discipline is used inside the SwapView’s format:
HStack(spacing: 12) {
CustomTextField(textual content: $fromAmount, discipline: .from, focusedField: $focusedField)
.body(maxWidth: .infinity, maxHeight: 40)
Button(motion: { showFromTokenSelect = true }) {
TokenButton(token: selectedFromToken, motion: { showFromTokenSelect = true })
}
.body(width: 140)
}
.body(top: 40)
Anticipated Conduct:
- Textual content discipline ought to preserve its body dimension
- Font ought to scale down routinely for longer numbers
- Structure ought to stay secure no matter enter size
Present Conduct:
- Textual content discipline expands past its body
- Structure breaks when coming into lengthy numbers
- Cursor place turns into inconsistent
Setting:
- iOS 15.0+
- SwiftUI
- Xcode 14+
You could find the entire mission at: https://github.com/lexypaul13/DegenTrader
Any assist in fixing this format subject whereas sustaining the font scaling performance can be enormously appreciated.