Add REFormattedNumberField as a dependency

This commit is contained in:
Roman Efimov
2013-04-02 10:19:23 -05:00
parent d1a3e64c45
commit 29da1eebee
15 changed files with 1005 additions and 764 deletions

View File

@@ -1,2 +1,3 @@
platform :ios, '5.0'
pod 'REFormattedNumberField'
pod 'SDWebImage'

View File

@@ -1,13 +1,16 @@
PODS:
- REFormattedNumberField (1.0.2)
- SDWebImage (3.2):
- SDWebImage/MapKit (= 3.2)
- SDWebImage/MapKit (3.2)
DEPENDENCIES:
- REFormattedNumberField
- SDWebImage
SPEC CHECKSUMS:
REFormattedNumberField: a8031ed845b21935a8bd8f5a5bdcb735a4947d94
SDWebImage: 8082fe8d658ccafaaecd9e5ecda12ed01f09ba9c
SDWebImage/MapKit: 8082fe8d658ccafaaecd9e5ecda12ed01f09ba9c

View File

@@ -0,0 +1 @@
../../REFormattedNumberField/REFormattedNumberField/REFormattedNumberField.h

View File

@@ -0,0 +1 @@
../../REFormattedNumberField/REFormattedNumberField/REFormattedNumberField.h

View File

@@ -1,6 +1,28 @@
# Acknowledgements
This application makes use of the following third party libraries:
## REFormattedNumberField
Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego).
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.
## SDWebImage
Copyright (c) 2009 Olivier Poitrey <rs@dailymotion.com>

View File

@@ -12,6 +12,32 @@
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
<dict>
<key>FooterText</key>
<string>Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego).
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.</string>
<key>Title</key>
<string>REFormattedNumberField</string>
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
<dict>
<key>FooterText</key>
<string>Copyright (c) 2009 Olivier Poitrey &lt;rs@dailymotion.com&gt;

View File

@@ -1,7 +1,7 @@
ALWAYS_SEARCH_USER_PATHS = YES
HEADER_SEARCH_PATHS = ${PODS_HEADERS_SEARCH_PATHS}
OTHER_LDFLAGS = -ObjC -framework ImageIO -framework MapKit
PODS_BUILD_HEADERS_SEARCH_PATHS = "${PODS_ROOT}/BuildHeaders" "${PODS_ROOT}/BuildHeaders/SDWebImage"
PODS_BUILD_HEADERS_SEARCH_PATHS = "${PODS_ROOT}/BuildHeaders" "${PODS_ROOT}/BuildHeaders/REFormattedNumberField" "${PODS_ROOT}/BuildHeaders/SDWebImage"
PODS_HEADERS_SEARCH_PATHS = ${PODS_PUBLIC_HEADERS_SEARCH_PATHS}
PODS_PUBLIC_HEADERS_SEARCH_PATHS = "${PODS_ROOT}/Headers" "${PODS_ROOT}/Headers/SDWebImage"
PODS_PUBLIC_HEADERS_SEARCH_PATHS = "${PODS_ROOT}/Headers" "${PODS_ROOT}/Headers/REFormattedNumberField" "${PODS_ROOT}/Headers/SDWebImage"
PODS_ROOT = ${SRCROOT}/Pods

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego).
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.

View File

@@ -0,0 +1,88 @@
# REFormattedNumberField
UITextField subclass that allows numeric input in a predefined format.
![Screenshot of REFormattedNumberField](https://github.com/romaonthego/REFormattedNumberField/raw/master/Screenshot.png "REFormattedNumberField Screenshot")
## Requirements
* Xcode 4.5 or higher
* Apple LLVM compiler
* iOS 5.0 or higher
* ARC
## Demo
Build and run the `REFormattedNumberFieldExample` project in Xcode to see `REFormattedNumberField` in action.
## Installation
### via CocoaPods
The recommended approach for installating REFormattedNumberField is via the [CocoaPods](http://cocoapods.org/) package manager, as it provides flexible dependency management and dead simple installation.
Install CocoaPods if not already available:
``` bash
$ [sudo] gem install cocoapods
$ pod setup
```
Edit your Podfile and add REFormattedNumberField:
``` bash
$ edit Podfile
platform :ios, '5.0'
pod 'REFormattedNumberField', '~> 1.0.2'
```
Install into your Xcode project:
``` bash
$ pod install
```
### Simple 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.
``` objective-c
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
- https://github.com/romaonthego
- https://twitter.com/romaonthego
- romefimov@gmail.com
## 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.

View File

@@ -0,0 +1,17 @@
Pod::Spec.new do |s|
s.name = 'REFormattedNumberField'
s.version = '1.0.2'
s.authors = { 'Roman Efimov' => 'romefimov@gmail.com' }
s.homepage = 'https://github.com/romaonthego/REFormattedNumberField'
s.summary = 'UITextField subclass that allows number input in a predefined format.'
s.source = { :git => 'https://github.com/romaonthego/REFormattedNumberField.git',
:tag => '1.0.2' }
s.license = { :type => "MIT", :file => "LICENSE" }
s.platform = :ios, '5.0'
s.requires_arc = true
s.source_files = 'REFormattedNumberField'
s.public_header_files = 'REFormattedNumberField/*.h'
s.ios.deployment_target = '5.0'
end

View File

@@ -0,0 +1,33 @@
//
// REFormattedNumberField.h
// REFormattedNumberField
//
// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego)
//
// 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.
//
#import <UIKit/UIKit.h>
@interface REFormattedNumberField : UITextField
@property (copy, readwrite, nonatomic) NSString *format;
@property (copy, readonly, nonatomic) NSString *unformattedText;
@end

View File

@@ -0,0 +1,116 @@
//
// REFormattedNumberField.m
// REFormattedNumberField
//
// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego)
//
// 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.
//
#import "REFormattedNumberField.h"
@implementation REFormattedNumberField
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:(CGRect)frame];
if (self) {
self.keyboardType = UIKeyboardTypeNumberPad;
self.format = @"X";
[self addTarget:self action:@selector(formatInput:) forControlEvents:UIControlEventEditingChanged];
}
return self;
}
- (NSString *)string:(NSString *)string withNumberFormat:(NSString *)format
{
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\D" options:NSRegularExpressionCaseInsensitive error:NULL];
NSString *stripped = [regex stringByReplacingMatchesInString:string options:0 range:NSMakeRange(0, string.length) withTemplate:@""];
NSMutableArray *patterns = [[NSMutableArray alloc] init];
NSMutableArray *separators = [[NSMutableArray alloc] init];
[patterns addObject:@0];
NSInteger maxLength = 0;
for (NSInteger i = 0; i < [format length]; i++) {
NSString *character = [format substringWithRange:NSMakeRange(i, 1)];
if ([character isEqualToString:@"X"]) {
maxLength++;
NSNumber *number = [patterns objectAtIndex:patterns.count - 1];
number = @(number.integerValue + 1);
[patterns replaceObjectAtIndex:patterns.count - 1 withObject:number];
} else {
[patterns addObject:@0];
[separators addObject:character];
}
}
if (stripped.length > maxLength)
stripped = [stripped substringToIndex:maxLength];
NSString *match = @"";
NSString *replace = @"";
NSMutableArray *expressions = [[NSMutableArray alloc] init];
for (NSInteger i = 0; i < patterns.count; i++) {
NSString *currentMatch = [match stringByAppendingString:@"(\\d+)"];
match = [match stringByAppendingString:[NSString stringWithFormat:@"(\\d{%d})", ((NSNumber *)[patterns objectAtIndex:i]).integerValue]];
NSString *template;
if (i == 0) {
template = [NSString stringWithFormat:@"$%i", i+1];
} else {
template = [NSString stringWithFormat:@"%@$%i", [separators objectAtIndex:i-1], i+1];
}
replace = [replace stringByAppendingString:template];
[expressions addObject:@{@"match": currentMatch, @"replace": replace}];
}
NSString *result = [stripped copy];
for (NSDictionary *exp in expressions) {
NSString *match = [exp objectForKey:@"match"];
NSString *replace = [exp objectForKey:@"replace"];
NSString *modifiedString = [stripped stringByReplacingOccurrencesOfString:match
withString:replace
options:NSRegularExpressionSearch
range:NSMakeRange(0, stripped.length)];
if (![modifiedString isEqualToString:stripped])
result = modifiedString;
}
return result;
}
- (void)formatInput:(UITextField *)textField
{
__typeof (&*self) __weak weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
textField.text = [weakSelf string:textField.text withNumberFormat:_format];
});
}
- (NSString *)unformattedText
{
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\D" options:NSRegularExpressionCaseInsensitive error:NULL];
return [regex stringByReplacingMatchesInString:self.text options:0 range:NSMakeRange(0, self.text.length) withTemplate:@""];
}
@end

View File

@@ -30,7 +30,6 @@
30DB067816E934AD006C9530 /* RETableViewManager.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 30DB066516E934AD006C9530 /* RETableViewManager.bundle */; };
30DB067916E934AD006C9530 /* RETableViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 30DB066716E934AD006C9530 /* RETableViewManager.m */; };
30DB067A16E934AD006C9530 /* RETableViewSection.m in Sources */ = {isa = PBXBuildFile; fileRef = 30DB066916E934AD006C9530 /* RETableViewSection.m */; };
30DB067E16E934C5006C9530 /* REFormattedNumberField.m in Sources */ = {isa = PBXBuildFile; fileRef = 30DB067D16E934C5006C9530 /* REFormattedNumberField.m */; };
30EF93B316E039B800B84981 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 30EF93B216E039B800B84981 /* UIKit.framework */; };
30EF93B516E039B800B84981 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 30EF93B416E039B800B84981 /* Foundation.framework */; };
30EF93B716E039B800B84981 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 30EF93B616E039B800B84981 /* CoreGraphics.framework */; };
@@ -89,8 +88,6 @@
30DB066716E934AD006C9530 /* RETableViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RETableViewManager.m; sourceTree = "<group>"; };
30DB066816E934AD006C9530 /* RETableViewSection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RETableViewSection.h; sourceTree = "<group>"; };
30DB066916E934AD006C9530 /* RETableViewSection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RETableViewSection.m; sourceTree = "<group>"; };
30DB067C16E934C5006C9530 /* REFormattedNumberField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = REFormattedNumberField.h; sourceTree = "<group>"; };
30DB067D16E934C5006C9530 /* REFormattedNumberField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = REFormattedNumberField.m; sourceTree = "<group>"; };
30EF93AF16E039B800B84981 /* RETableViewManagerExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RETableViewManagerExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
30EF93B216E039B800B84981 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
30EF93B416E039B800B84981 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@@ -223,20 +220,9 @@
path = Items;
sourceTree = "<group>";
};
30DB067B16E934C5006C9530 /* REFormattedNumberField */ = {
isa = PBXGroup;
children = (
30DB067C16E934C5006C9530 /* REFormattedNumberField.h */,
30DB067D16E934C5006C9530 /* REFormattedNumberField.m */,
);
name = REFormattedNumberField;
path = ../REFormattedNumberField;
sourceTree = "<group>";
};
30EF93A616E039B800B84981 = {
isa = PBXGroup;
children = (
30DB067B16E934C5006C9530 /* REFormattedNumberField */,
30DB064616E934AD006C9530 /* RETableViewManager */,
30EF93B816E039B800B84981 /* RETableViewManagerExample */,
30EF93B116E039B800B84981 /* Frameworks */,
@@ -391,7 +377,6 @@
30DB067716E934AD006C9530 /* RETableViewItem.m in Sources */,
30DB067916E934AD006C9530 /* RETableViewManager.m in Sources */,
30DB067A16E934AD006C9530 /* RETableViewSection.m in Sources */,
30DB067E16E934C5006C9530 /* REFormattedNumberField.m in Sources */,
302D2150170B25B10085654F /* ControlsViewController.m in Sources */,
302D2151170B25B10085654F /* ListViewController.m in Sources */,
302D2152170B25B10085654F /* RootViewController.m in Sources */,

View File

@@ -63,7 +63,7 @@
NSURL *userpicURL = [NSURL URLWithString:[dictionary objectForKey:@"userpic_url"]];
NSURL *imageURL = [NSURL URLWithString:[dictionary objectForKey:@"image_url"]];
// Create section with header view
// Create section with a header view
//
section = [[RETableViewSection alloc] initWithHeaderView:[ListHeaderView headerViewWithImageURL:userpicURL username:username]];
[_manager addSection:section];