UITextField-based control for (NS)Measurement values input.

Overview

MeasurementTextField

CI Status Version License Platform

UITextField-based control for (NS)Measurement values input. Provides type-safe keyboard and picker based input of different measurements(such as length, mass, speed etc). See example app for API details.

Screenshots

Screenshot 1Screenshot 2

Example Usage

First of all you need to import MeasurementTextField:

import MeasurementTextField

Need text field for angle input? Just write:

let angleTextField = MeasurementTextField<UnitAngle>(inputType: .keyboard(.degrees))

Instead of UnitAngle you can use any Dimension type defined in Foundation or implement own Dimension subclass if you need something special. Then to obtain Measurement value inputted by user just use value property:

if let value = angleTextField.value {
    let formatter = MeasurementFormatter()
    print("Your input is \(formatter.string(from: value))!")
} else {
    print("You cleared the field!")
}

Degrees input is not enough? Want also arc minutes and arc seconds? Just use another input type:

let angleTextField = MeasurementTextField<UnitAngle>(inputType: .picker([
    PickerColumn(unit: UnitAngle.degrees, range: 0...360, step: 1.0), // `step` is optional here, 1.0 by default
    PickerColumn(unit: UnitAngle.arcMinutes, range: 0...60),
    PickerColumn(unit: UnitAngle.arcSeconds, range: 0...60),
]))

Need to be notified when value is changed? Just subscribe on UIControlEvents.valueChanged:

@objc private func onAngleValueChanged() {
    print("Angle value was changed!")
}
angleTextField.addTarget(self, action: #selector(onAngleValueChanged), for: .valueChanged)

Customization

To change text color of measurement unit label for .keyboard input type just change tintColor:

angleTextField.tintColor = .red

Want to remove it completely? Just pass showMeasureUnit: false in input type configuration:

let angleTextField = MeasurementTextField<UnitAngle>(inputType: .keyboard(.degrees, showMeasureUnit: false))

Also be aware that MeasurementTextField is an usual UITextField, so you can use all APIs provided by it, except of textField(_:shouldChangeCharactersIn:replacementString:) delegate method.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • Swift 4

Issues

If you need some feature or you found a bug feel free to open an issue.

Installation

MeasurementTextField is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'MeasurementTextField'

Author

SiarheiFedartsou, [email protected]

License

MeasurementTextField is available under the MIT license. See the LICENSE file for more info.

You might also like...
iOS - Subclass of UITextField to achieve autocompletion for Place Search like Google Places, Uber and Much more apps having maps.

MVAutocompletePlaceSearchTextField iOS - Subclass of UITextField to achieve autocompletion for Place Search like Google Places, Uber and Much more app

Subclass of UITextField that shows inline suggestions while typing.
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

UITextfield subclass with autocomplete menu. For iOS.
UITextfield subclass with autocomplete menu. For iOS.

MLPAutoCompleteTextField "We believe that every tap a user makes drains a tiny bit of their energy and patience. Typing is one of the biggest expendit

UITextField with underline and left image
UITextField with underline and left image

TJTextField UITextField with underline and left image Version: 1.0 Features Add image in UITextField Left text pedding Underline whole UITextField Sho

UITextField and UITextView subclasses with placeholders that change into floating labels when the fields are populated with text.
UITextField and UITextView subclasses with placeholders that change into floating labels when the fields are populated with text.

Deprecated Please use JVFloatLabeledTextField instead or feel free to chime in on an issue if you'd like to take over the repo. RPFloatingPlaceholders

UITextField that automatically formats text to display in the currency format
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

UITextField that support currency in the right way.
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

Animated UITextField and UITextView replacement for iOS
Animated UITextField and UITextView replacement for iOS

AnimatedTextInput iOS custom text input component used in the Jobandtalent app. Installation Use cocoapods to install this custom control in your proj

UITextField subclass with autocompletion suggestions list
UITextField subclass with autocompletion suggestions list

SearchTextField Overview SearchTextField is a subclass of UITextField, written in Swift that makes really easy the ability to show an autocomplete sug

Comments
Owner
Siarhei Fiedartsou
Siarhei Fiedartsou
HTYTextField A UITextField with bouncy placeholder.

HTYTextField - A UITextField with bouncy placeholder. Screenshot Installation CocoaPods Add the dependency to your Podfile

Hanton Yang 312 Nov 13, 2022
Fully-wrapped UITextField made to work entirely in SwiftUI

iTextField ⌨️ A fully-wrapped `UITextField` that works entirely in SwiftUI. ?? Get Started | Examples | Customize | Install | Get Started Install iTex

Benjamin Sage 89 Jan 2, 2023
UITextField character counter with lovable UX 💖. No math skills required 🙃.

TextFieldCounter UITextField character counter with lovable UX ??. No math skills required ??. Features Set max length of UITextField. A beautiful an

Fabricio Serralvo 434 Dec 22, 2022
🏄‍♂️ UITextField-Navigation makes it easier to navigate between UITextFields and UITextViews

' __________________ _______ _________ _______ _________ _______ _ ______ ' |\ /|\__ __/\__ __/( ____ \|\ /

Thanh Pham 446 Nov 24, 2022
Animated UITextField enhance UX for the user by giving clarity that they are focused

JDCircularProgress JDTextField is animateable UITextField that can significantly enhance your user's experiences and set your app apart from the rest

Jawad Ali 22 Nov 17, 2022
Animated Subclass of UITextField created with CABasicAnimation and CAShapeLayer

JDAnimatedTextField JDAnimatedTextField is animateable UITextField that can significantly enhance your user's experiences and set your app apart from

Jawad Ali 25 Dec 13, 2022
This project will add a done button on your UITextField and UITextView

This project will add a done button on your UITextField and UITextView

Botla Venkatesh 0 Nov 23, 2021
UITextField subclass with floating labels

JVFloatLabeledTextField JVFloatLabeledTextField is the first implementation of a UX pattern that has come to be known the "Float Label Pattern". Due t

Jared Verdi 7.2k Jan 2, 2023
UITextField category that adds shake animation

UITextField category that adds a shake animation like the password field of the OsX login screen. Screenshot Setup with CocoaPods pod 'UITextField+Sha

Andrea Mazzini 749 Dec 13, 2022
UITextField extension in Swift that adds shake animation

UITextField-Shake-Swift UITextField extension in Swift that adds shake animation Initially created by Andrea Mazzini (using Objective-C) on 08/02/14:

null 15 Jul 20, 2021