A SwiftUI package that provides a custom currency entry view for capturing currency values, with animations and styling similar to the built-in calculator app on iOS.
- $ Currency value entry 1 character at-a-time
- 🔴 Customizable color and digit presentation
- 📱 Full SwiftUI implementation
- iOS 17.0+
- Swift 6+
- Xcode 16.0+
Add CurrencyEntryView to your project through Xcode:
- File > Add Packages
- Enter package URL:
https://github.com/jcgohlke/CurrencyEntryView.git - Select version requirements
- Click Add Package
- First, create a view to hold the CurrencyEntryView. You'll need a view to display the output of the entry view, so you could build something like the following:
import CurrencyEntryView
import SwiftUI
struct CurrencyDisplayView: View {
static let currencyCode = "USD"
@State private var service = CurrencyEntryService(currencyCode: CurrencyInputView.currencyCode) // 1
var body: some View {
VStack {
Text(service.value, format: .currency(code: CurrencyInputView.currencyCode).decimalSeparator(strategy: .automatic)) // 3
.font(.system(size: 30))
CurrencyEntryView(service: $service) // 2
}
}
}- Create a state property to hold the currency entry service. Provide a valid 3-character currency code as defined by ISO-4217. If the code is not recognized the view will default to USD.
- Set up your enclosing view however you like, but be sure to send a binding to the CurrencyEntryView of the service you defined in step 1.
- Use the service to get the output entered by the user to display here or anywhere.
You can customize the appearance of the entry buttons with changes to color, size, and the spacing between them. The font size of the digits will scale up and down with the size of the button.
CurrencyEntryView(service: $service, backgroundColor: .blue, buttonSize: 60, spacing: 10)Alternatively, you can use the CircleButton and CurrencyEntryService to create alternate layouts of the keys if the standard view provided in CurrencyEntryView is not ideal for your needs. See the documentation in Xcode provided with those types to learn more, or inspect the CurrencyEntryView file to see how those types were used for the standard view.