ATMTextField is a custom SwiftUI text field for entering currency amounts in an ATM-style format.
It handles input formatting automatically based on the provided currencyCode and exposes a Decimal value for easy usage—no manual string parsing or conversion needed.
This component is used in my own app, Dreams, available on the App Store.
Features
- Seamless conversion between formatted string and Decimal value
- Locale-aware currency formatting using currencyCode
- ATM-style digit entry (e.g. typing “1234” results in “€12.34”)
- Optional placeholder styling for zero value
- Configurable maximum input value
- No dependencies
You can install ATMTextField using Swift Package Manager. Add the following dependency to your Package.swift or through Xcode:
.package(url: "https://github.com/marcelvoss/ATMTextField.git", .upToNextMajor(from: "1.0.0"))Using ATMTextField is simple. Declare a @State property of type Decimal and bind it to the amount parameter:
@State private var currencyValue: Decimal = .zero
CurrencyTextField(amount: $currencyValue, currencyCode: "EUR")By default:
- The field treats 0 as a placeholder value and styles it with a secondary color.
- The maximum value is set to
999_999_999.99, but this can be customized.
You can modify these behaviors:
ATMTextField(
amount: $currencyValue,
currencyCode: "USD",
treatZeroAsPlaceholder: false,
maximumValue: 1_000_000
)ATMTextField is available under the MIT license. See the LICENSE file for details.
