Code Monkey home page Code Monkey logo

ftctextentryformatting's Introduction

Overview

FTCTextEntryFormatting is a component for formatting input data in realtime.

Installation

pod 'FTCTextEntryFormatting', :git => 'https://github.com/cft-dev/FTCTextEntryFormatting.git', :tag => '1.0.5'

Standalone usage

Example for cell phone. See Demo project for more details.

import FTCTextEntryFormatting

class EntryViewController: UIViewController
{
	@IBOutlet var textField: UITextField!

	// required strong stored
	var textFieldFormatCoordinator: FTCTextFieldFormatCoordinator!

	override func viewDidLoad()
	{
		super.viewDidLoad()

		self.textFieldFormatCoordinator = FTCTextFieldFormatCoordinator(textField: self.textField)

		let formattingConfig = FTCTextEntryFormattingConfigFactory.mobilePhoneConfig(with: "+7 (___) ___-__-__",
		                                                                             maskChar: "_")
		self.textFieldFormatCoordinator.apply(formattingConfig: formattingConfig)
	}
}

Custom usage

  1. Create adopter of FTCTextEntryEditingInputFilter
import FTCTextEntryFormatting

class CustomEditingInputFilter : NSObject, FTCTextEntryEditingInputFilter
{
	func replaceSubstring(in originalString: String, at range: NSRange, with replacement: String) -> FTCFilteredString
	{
		...
	}
}
  1. Create adopter of FTCTextEntryFormatter
class CustomFormatter : NSObject, FTCTextEntryFormatter
{
	func raw(fromFormatted formattedValue: String?) -> String
	{
		...
	}

	func formatted(fromRaw rawValue: String?) -> String
	{
		...
	}

	func rangeInFormattedValue(for rangeInRawValue: NSRange, inRawValue rawValue: String?) -> NSRange
	{
		...
	}

	func rangeInRawValue(for rangeInFormattedValue: NSRange, inFormattedValue formattedValue: String?) -> NSRange
	{
		...
	}
}
  1. Create adopter of FTCTextEntryNotEditingInputFilter
class CustomNotEditingInputFilter : NSObject, FTCTextEntryNotEditingInputFilter
{
	func filterString(_ string: String) -> String
	{
		...
	}
}
  1. Use it
class EntryViewController: UIViewController
{
	@IBOutlet var textField: UITextField!

	// required strong stored
	var textFieldFormatCoordinator: FTCTextFieldFormatCoordinator!

	override func viewDidLoad()
	{
		super.viewDidLoad()

		self.textFieldFormatCoordinator = FTCTextFieldFormatCoordinator(textField: self.textField)

		let formattingConfig = FTCTextEntryFormattingConfig()
		formattingConfig.editingInputFilter = CustomEditingInputFilter()
		formattingConfig.editingFormatter = CustomFormatter()
		formattingConfig.notEditingInputFilter = CustomNotEditingInputFilter()
		formattingConfig.notEditingFormatter = CustomFormatter()

		self.textFieldFormatCoordinator.apply(formattingConfig: formattingConfig)
	}
}

Generic input filters

FTCDigitsValueFilter – Allows only digits symbols.

FTCNoFilteringFilter – Allows any symbol.

FTCLimitedLengthInputFilter – Allows any symbol. Constraining input by length.

FTCToUpperCaseInputFilter – Allows any symbol. Turns case to upper.

License

MIT

ftctextentryformatting's People

Contributors

dmoroz0v avatar mrhard4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

mrhard4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.