UITextField realtime currency formatter - format while typing

Overview

Objective-C Realtime Currency Formatter

License: MIT

An extremely simple Objective-C class for formatting currencies. Ready to work with the UITextFieldDelegate and format currencies while typing.

How to use

  • Download or clone this repository
  • Copy BBRealTimeCurrencyFormatter.h and BBRealTimeCurrencyFormatter.m to your project
  • Import BBRealTimeCurrencyFormatter.h on your implementation file (.m extension!)
  • Ensure your controller conforms to the UITextFieldDelegate protocol
  • Implement the UITextFieldDelegate method textField:shouldChangeCharactersInRange:replacementString: and invoke the BBRealTimeCurrencyFormatter's method textField:shouldChangeCharactersInRange:replacementString:
  • Done!

Example

// MyViewController.m

//#import "MyViewController.h"
#import "BBRealTimeCurrencyFormatter.h" //Import the BBRealTime class

// Ensure it conforms to the UITextFieldDelegate protocol
@interface ViewController () <UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *tfCurrency; //UITextField that will receive the formatted string
@end

@implementation ViewController

- (void)viewDidLoad{
    [super viewDidLoad];
    [[self tfCurrency] setDelegate:self]; // Ensure the field delegates its events to this controller
}

//Implement UITextFieldDelegate method
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

    //Format the textfiled
    [BBRealTimeCurrencyFormatter textField:textField shouldChangeCharactersInRange:range replacementString:string];
    return NO;
}

@end

License

MIT License

Copyright (c) 2016-2017 Kaio Medau

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
You might also like...
Safely access Apple's SF Symbols using static typing
Safely access Apple's SF Symbols using static typing

Supported Versions • Motivation • Installation • Usage • Contributing • License • Issues • Pull Requests Supported Versions SFSafeSymbols supports mul

Modern Swift wrapper for Keychain Services API with the benefits of static typing

SwiftyKeychainKit SwiftyKeychainKit is a simple Swift wrapper for Keychain Services API with the benefits of static typing. Define your keys in one pl

Swift CLI for strong-typing images, colors, storyboards, fonts and localizations

Shark Shark is a Swift command line tool that generates type safe enums for your images, colors, storyboards, fonts and localizations. Because Shark r

TextFormation - Rules system for live typing completions

TextFormation TextFormation is simple rule system that can be used to implement

A Swift Formatter Kit
A Swift Formatter Kit

Format A Swift formatter kit. Simple formatting syntax for decimal numbers, currency, mass, addresses, ordinal numbers and hexadecimal colors. Usage I

🪞 Formatter JSON delightfully.

SwiftJSONFormatter 🪞 Formatter JSON delightfully. Highlights Beautify and minify JSON strings. Keep dictionary key order stable. Work with invalid JS

Swift Date Formatter

Swift Date Formatter Date Formatter - Sample code on how to use Date Formatter in swift language Author: Denow Cleetus For OSSE Assignment 4 Group 24

A number formatter that adds K for thousands, M for millions and B for billions

KMBFormatter A number formatter that adds K for thousands, M for millions and B for billions Sample usage: let formatter = KMBFormatter() formatter.st

🎗 Super lightweight ISO8601 Date Formatter in Swift
🎗 Super lightweight ISO8601 Date Formatter in Swift

ISO8601 ❤️ Support my apps ❤️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut mana

Wrapper for the Prettier code formatter written in Swift

Prettier A wrapper for the Prettier code formatter written in Swift. The package

Snowonder - 🔮 Magical import declarations formatter for Xcode
Snowonder - 🔮 Magical import declarations formatter for Xcode

Snowonder is Xcode Extension that adds some convenient formatting operations for Import Declarations. This extension is created with latest stable Swi

TextFieldFormatter - Simple Text Formatter (Credit Card Number, Phone Number, Serial Number etc.)
TextFieldFormatter - Simple Text Formatter (Credit Card Number, Phone Number, Serial Number etc.)

TextFieldFormatter Simple Text Formatter (Credit Card Number, Phone Number, Seri

🎗 Super lightweight ISO8601 Date Formatter in Swift
🎗 Super lightweight ISO8601 Date Formatter in Swift

ISO8601 ❤️ Support my apps ❤️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut mana

Jay - Pure-Swift JSON parser & formatter. Fully streamable input and output. Linux & OS X ready.

Pure-Swift JSON parser & formatter. Fully streamable input and output. Linux & OS X ready. Replacement for NSJSONSerialization.

Advanced usage of UIAlertController and pickers based on it: Telegram, Contacts, Location, PhotoLibrary, Country, Phone Code, Currency, Date...
Advanced usage of UIAlertController and pickers based on it: Telegram, Contacts, Location, PhotoLibrary, Country, Phone Code, Currency, Date...

Alerts & Pickers Advanced usage of native UIAlertController with TextField, TextView, DatePicker, PickerView, TableView, CollectionView and MapView. F

A Currency Converter & Calculator IOS application to check, convert and calculate to popular currencies to your favorite ones.
A Currency Converter & Calculator IOS application to check, convert and calculate to popular currencies to your favorite ones.

A Currency Converter & Calculator IOS application to check, convert and calculate to popular currencies to your favorite ones.

Currency Converter project coded by SwiftUI and Swift5
Currency Converter project coded by SwiftUI and Swift5

SwiftUI-Currency-Converter Currency Converter project coded by SwiftUI and Swift5 Features Implemented with SwiftUI Supports darkmode for sure SwiftUI

Advanced usage of UIAlertController and pickers based on it: Telegram, Contacts, Location, PhotoLibrary, Country, Phone Code, Currency, Date...
Advanced usage of UIAlertController and pickers based on it: Telegram, Contacts, Location, PhotoLibrary, Country, Phone Code, Currency, Date...

Alerts & Pickers Advanced usage of native UIAlertController with TextField, TextView, DatePicker, PickerView, TableView, CollectionView and MapView. F

Currency Converter - Free and Quick Converter calculates money quick and easy way to see live foreign exchange rates.
Currency Converter - Free and Quick Converter calculates money quick and easy way to see live foreign exchange rates.

Currency Converter - Free and Quick Converter calculates money quick and easy way to see live foreign exchange rates. This app is available in the App

Comments
  • Error when entering more than $nnn,nnn,nnn.nn

    Error when entering more than $nnn,nnn,nnn.nn

    Just downloaded and ran sample, looks like there is something going in when entering into the hundred-thousand dollar range. The numbers seem to be -1 of what is pressed/entered in that range.

    For example pressing 5 up to $55,555.55 is fine, but press 5 again then output in textfield is $555,555.54. Press 5 again then output is $5,555,555.33. Press 5 again then output is $55,555,552.11

    bug 
    opened by rjpalermo1 1
Owner
Kaio Medau
Kaio Medau
🎗 Super lightweight ISO8601 Date Formatter in Swift

ISO8601 ❤️ Support my apps ❤️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut mana

Khoa 19 May 12, 2020
Swift value types for working with money & currency

Money Money is a Swift framework for iOS, watchOS, tvOS and OS X. It provides types and functionality to represent, calculate and convert money in the

Daniel Thorpe 932 Dec 2, 2022
Texstyle allows you to format iOS attributed strings easily.

Texstyle allows you to format attributed strings easily. Features Applying attributes with strong typing and autocompletion Cache for attributes Subst

Rosberry 79 Sep 9, 2022
Subclass of UITextField that shows inline suggestions while typing.

AutocompleteField Subclass of UITextField that shows inline suggestions while typing. Plug and play replacement for UITextField. Delimiter support. Pe

Filip Stefansson 663 Dec 6, 2022
UITextField that automatically formats text to display in the currency format

CurrencyTextField The numbers that the user enters in the field are automatically formatted to display in the dollar amount format. For example, if th

Richa Deshmukh 49 Sep 28, 2022
Date Formatter Pool - is a small utility that creates and stores your Date Formatter for simpler reuse

Date Formatter Pool Date Formatter Pool - is a small utility that creates and stores your Date Formatter for simpler reuse Installation is available i

Aleksei Artemev 13 Sep 6, 2022
Currency text field formatter available for UIKit and SwiftUI 💶✏️

CurrencyText provides lightweight libraries for formating text field text as currency, available for both UIKit and SwiftUI. Its main core, the Curren

Felipe Lefèvre Marino 183 Dec 15, 2022
An Xcode formatter plug-in to format your swift code.

Swimat Swimat is an Xcode plug-in to format your Swift code. Preview Installation There are three way to install. Install via homebrew-cask # Homebrew

Jintin 1.6k Jan 7, 2023
UITextField that support currency in the right way.

PLCurrencyTextField Summary PLCurrencyTextField provides simple and user friendly support for the amount in the currency. Usage To start using the com

Łukasz Śliwiński 96 Nov 14, 2022
null 13 Oct 28, 2022