Code Monkey home page Code Monkey logo

reformattednumberfield's Introduction

REFormattedNumberField

UITextField subclass that allows numeric input in a predefined format.

REFormattedNumberField Screenshot

Requirements

  • Xcode 6 or higher
  • Apple LLVM compiler
  • iOS 7.0 or higher
  • ARC

Demo

Build and run the REFormattedNumberFieldExample project in Xcode to see REFormattedNumberField in action.

Installation

CocoaPods

The recommended approach for installating REFormattedNumberField is via the CocoaPods package manager, as it provides flexible dependency management and dead simple installation. For best results, it is recommended that you install via CocoaPods >= 0.28.0 using Git >= 1.8.0 installed via Homebrew.

Install CocoaPods if not already available:

$ [sudo] gem install cocoapods
$ pod setup

Change to the directory of your Xcode project:

$ cd /path/to/MyProject
$ touch Podfile
$ edit Podfile

Edit your Podfile and add REFormattedNumberField:

platform :ios, '7.0'
pod 'REFormattedNumberField', '~> 1.1.5'

Install into your Xcode project:

$ pod install

Open your project in Xcode from the .xcworkspace file (not the usual project file)

$ open MyProject.xcworkspace

Please note that if your installation fails, it may be because you are installing with a version of Git lower than CocoaPods is expecting. Please ensure that you are running Git >= 1.8.0 by executing git --version. You can get a full picture of the installation details by executing pod install --verbose.

Manual Install

All you need to do is drop REFormattedNumberField files into your project, and add #include "REFormattedNumberField.h" to the top of classes that will use it.

Example Usage

Pretty much all you need is just to specify format NSString, where X are digits and all other characters are separators.

REFormattedNumberField *phoneField1 = [[REFormattedNumberField alloc] initWithFrame:CGRectMake(20, 20, 280, 30)];
phoneField1.format = @"(XXX) XXX-XXXX";
[self.view addSubview:phoneField1];

REFormattedNumberField *phoneField2 = [[REFormattedNumberField alloc] initWithFrame:CGRectMake(20, 80, 280, 30)];
phoneField2.format = @"+X (XXX) XXX-XXXX";
[self.view addSubview:phoneField2];

REFormattedNumberField *ccField = [[REFormattedNumberField alloc] initWithFrame:CGRectMake(20, 140, 280, 30)];
ccField.format = @"XXXX XXXX XXXX XXXX";
[self.view addSubview:ccField];

REFormattedNumberField *ccExpirationField = [[REFormattedNumberField alloc] initWithFrame:CGRectMake(20, 200, 280, 30)];
ccExpirationField.format = @"XX/XX";
[self.view addSubview:ccExpirationField];

Contact

Roman Efimov

License

REFormattedNumberField is available under the MIT license.

Copyright © 2013 Roman Efimov.

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.

reformattednumberfield's People

Contributors

romaonthego avatar seaburg avatar xbeg9 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reformattednumberfield's Issues

Main thread blocking up for updating the textfield

iPad2 with iOS 5.1.1
main thread getting blocked for updating the text

iPad3 with iOS 6.0
Worked fine

It seems that the - (void)formatInput: method is continuously getting called even for a sigle character change

-[UITextField customOverlayContainer] SIGSTOP on iOS7

Hello,
On iOS7 can see interest issue. app stops due to this line: self.delegate = self
here is workaround and description for this issue: http://stackoverflow.com/questions/19758025/uitextfield-delegate-jumping-to-100-cpu-usage-and-crashing-upon-using-keyboard

#0  0x000000018c7fd5d0 in -[UITextField customOverlayContainer] ()
#1  0x000000018c7fd444 in -[UITextField automaticallySelectedOverlay] ()
#2  0x000000018c77f364 in -[UIKeyboardImpl inputOverlayContainer] ()
#3  0x000000018c5d3320 in -[UIKeyboardImpl updateTextCandidateView] ()
#4  0x000000018c5d2eac in -[UIKeyboardImpl finishSetInputMode:didChangeDirection:executionContext:] ()
#5  0x000000018c5d411c in -[UIKeyboardTaskExecutionContext returnExecutionToParent] ()
#6  0x000000018c5d411c in -[UIKeyboardTaskExecutionContext returnExecutionToParent] ()
#7  0x000000018c5d411c in -[UIKeyboardTaskExecutionContext returnExecutionToParent] ()
#8  0x000000018c5d12d8 in -[UIKeyboardTaskQueue continueExecutionOnMainThread] ()
#9  0x000000018c5d4530 in -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] ()
#10 0x000000018c5d0ed4 in -[UIKeyboardImpl setInputMode:userInitiated:] ()
#11 0x000000018c6b4938 in -[UIKeyboardImpl recomputeActiveInputModesFromList:] ()
#12 0x000000018c5d5040 in -[UIKeyboardImpl setDelegate:force:] ()
#13 0x000000018c5cccf8 in -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:] ()
#14 0x000000018c62ccc8 in -[UIResponder becomeFirstResponder] ()
#15 0x000000018c62cf8c in -[UIView(Hierarchy) becomeFirstResponder] ()
#16 0x000000018c6b20e4 in -[UITextField becomeFirstResponder] ()

Accessor for unformatted string

This is a request to add a readonly property that will allow for the following behaviour:

Given format : "XX/XXdXX" would allow to retrieve "XXXXXX" (i.e. the values for X only)

Another Example "12/32d43" would return "123243" using the above formatting

1.1.3 Breaks compatibility with 1.1.2

If you use [RENumberItem itemWithTitle:@"title" value:nil placeholder:@"placeholder"] then item.format is null and REFormattedNumberField will not accept any input.

In 1.1.2 the field would still accept any decimal characters.

Possible fixes.

  1. override -[RENumberItem initWithTitle:value:placeholder:] and forward to -[RENumberItem initWithTitle:value:placeholder:format:](making it a true designated initializer).
  2. Patch REFormattedNumberField to work with a nil item format.

This was especially annoying because even though we had pinned the version RETableViewManager it had specified a dependency on REFormattedNumberField of >= 1.1.2 and broke the current behaviour.

Add -awakefromnib support for IB

Hey,

To allow users to create an number field from IB I would suggest adding the following to your .m file

-(void) awakeFromNib {
[super awakeFromNib];
self.keyboardType = UIKeyboardTypeNumberPad;
self.format = @"X";
[self addTarget:self action:@selector(formatInput:) forControlEvents:UIControlEventEditingChanged];
}

@"Xm XXcm"

If you'll try to set @"Xm XXcm" as format, then "cm" at the end will not be shown.

Cannot set number in the format field

Ex format:

format:@"+62 XXX-XXXX"

When user start typing, it doesn't behave as expected.
What i want to achieve is to put +62 as a prefix.

Thanks

Fatal Exception: NSRangeException REFormattedNumberField.m line 99

iPhone 5 iOS 10.3.2
the latest lib version

Fatal Exception: NSRangeException
0  CoreFoundation                 0x1bf4bb3d __exceptionPreprocess
1  libobjc.A.dylib                0x1b1d3067 objc_exception_throw
2  CoreFoundation                 0x1bf4ba85 -[NSException initWithCoder:]
3  CoreFoundation                 0x1be75aed -[__NSCFString substringWithRange:]
4  MYAPP              0x961f7 -[REFormattedNumberField deleteBackward] (REFormattedNumberField.m:99)
5  UIKit                          0x21392921 -[UIKeyboardImpl deleteBackwardAndNotify:]
6  UIKit                          0x21574769 -[UIKeyboardImpl performKeyboardOutput:]
7  UIKit                          0x21574379 __55-[UIKeyboardImpl handleKeyboardInput:executionContext:]_block_invoke_2
8  UIKit                          0x211a02ff -[UIKeyboardTaskQueue continueExecutionOnMainThread]
9  UIKit                          0x211a2555 -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished]
10 UIKit                          0x211b3c53 -[UIKeyboardImpl prepareForSelectionChange]
11 UIKit                          0x211951f7 -[UIFieldEditor setAttributedText:andSetCaretSelectionAfterText:]
12 UIKit                          0x211b379d -[UIFieldEditor setText:andSetCaretSelectionAfterText:]
13 UIKit                          0x211b3561 -[UITextField setText:]
14 MYAPP              0x960b9 __38-[REFormattedNumberField formatInput:]_block_invoke (REFormattedNumberField.m:80)
15 libdispatch.dylib              0x1b619797 _dispatch_call_block_and_release
16 libdispatch.dylib              0x1b619783 _dispatch_client_callout
17 libdispatch.dylib              0x1b61dd05 _dispatch_main_queue_callback_4CF
18 CoreFoundation                 0x1bf07d69 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
19 CoreFoundation                 0x1bf05e19 __CFRunLoopRun
20 CoreFoundation                 0x1be591af CFRunLoopRunSpecific
21 CoreFoundation                 0x1be58fd1 CFRunLoopRunInMode
22 GraphicsServices               0x1d603b41 GSEventRunModal
23 UIKit                          0x211dae13 UIApplicationMain
24 MYAPP              0x98ec8 main (AppDelegate.swift:38)
25 libdyld.dylib                  0x1b6464eb start

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.