Skip to content

ferrousguy/CurrencyEntryView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

CurrencyEntryView

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.

Features

  • $ Currency value entry 1 character at-a-time
  • 🔴 Customizable color and digit presentation
  • 📱 Full SwiftUI implementation

Requirements

  • iOS 17.0+
  • Swift 6+
  • Xcode 16.0+

Installation

Swift Package Manager

Add CurrencyEntryView to your project through Xcode:

  1. File > Add Packages
  2. Enter package URL: https://github.com/jcgohlke/CurrencyEntryView.git
  3. Select version requirements
  4. Click Add Package

Usage

  1. 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
    }
  }
}
  1. 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.
  2. 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.
  3. Use the service to get the output entered by the user to display here or anywhere.

Customization

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.

About

A currency entry interface for SwiftUI.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages