-
-
Notifications
You must be signed in to change notification settings - Fork 953
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
285 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
Examples/Objective-C/Examples/Formatters/FormattersViewController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// FormattersViewController.h | ||
// XLForm | ||
// | ||
// Created by Freddy Henin on 12/29/14. | ||
// Copyright (c) 2014 Xmartlabs. All rights reserved. | ||
// | ||
|
||
#import "XLFormViewController.h" | ||
|
||
@interface FormattersViewController : XLFormViewController | ||
|
||
@end |
115 changes: 115 additions & 0 deletions
115
Examples/Objective-C/Examples/Formatters/FormattersViewController.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// | ||
// FormattersViewController.m | ||
// XLForm | ||
// | ||
// Created by Freddy Henin on 12/29/14. | ||
// Copyright (c) 2014 Xmartlabs. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
|
||
#import "XLForm.h" | ||
|
||
#import "FormattersViewController.h" | ||
|
||
#import <SHSPhoneComponent/SHSPhoneNumberFormatter+UserConfig.h> | ||
|
||
|
||
// Simple little class to demonstraite currency formatting. Unfortunally we have to subclass | ||
// NSNumberFormatter to work aroundn some long known rounding bugs with NSNumberFormatter | ||
// http://stackoverflow.com/questions/12580162/nsstring-to-nsdate-conversion-issue | ||
@interface CurrencyFormatter : NSNumberFormatter | ||
|
||
@property (readonly) NSDecimalNumberHandler *roundingBehavior; | ||
|
||
@end | ||
|
||
@implementation CurrencyFormatter | ||
|
||
- (id) init | ||
{ | ||
self = [super init]; | ||
if (self) { | ||
[self setNumberStyle: NSNumberFormatterCurrencyStyle]; | ||
[self setGeneratesDecimalNumbers:YES]; | ||
|
||
NSUInteger currencyScale = [self maximumFractionDigits]; | ||
|
||
_roundingBehavior = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundPlain scale:currencyScale raiseOnExactness:FALSE raiseOnOverflow:TRUE raiseOnUnderflow:TRUE raiseOnDivideByZero:TRUE]; | ||
|
||
} | ||
|
||
return self; | ||
} | ||
|
||
//- (BOOL)getObjectValue:(id *)anObject forString:(NSString *)string errorDescription:(NSString **)error | ||
//{ | ||
// NSDecimalNumber *number; | ||
// BOOL success = [super getObjectValue:&number forString:string errorDescription:error]; | ||
// | ||
// if (success) { | ||
// *anObject = [number decimalNumberByRoundingAccordingToBehavior:_roundingBehavior]; | ||
// } | ||
// else { | ||
// *anObject = nil; | ||
// } | ||
// | ||
// return success; | ||
//} | ||
|
||
@end | ||
|
||
@interface FormattersViewController () | ||
@end | ||
|
||
@implementation FormattersViewController | ||
|
||
-(id)init | ||
{ | ||
XLFormDescriptor * formDescriptor = [XLFormDescriptor formDescriptorWithTitle:@"Text Fields"]; | ||
XLFormSectionDescriptor * section; | ||
XLFormRowDescriptor * row; | ||
|
||
formDescriptor.assignFirstResponderOnShow = NO; | ||
|
||
section = [XLFormSectionDescriptor formSection]; | ||
section.title = @"NSFormatter Support"; | ||
section.footerTitle = @"Rows can be configured to use the formatter as you type or to toggle on and off during for display/editing. You will most likely need custom NSFormatter objects to do on the fly formatting since NSNumberFormatter is pretty limited in this regard."; | ||
[formDescriptor addFormSection:section]; | ||
|
||
// Phone | ||
SHSPhoneNumberFormatter *formatter = [[SHSPhoneNumberFormatter alloc] init]; | ||
[formatter setDefaultOutputPattern:@"(###) ###-####" imagePath:nil]; | ||
row = [XLFormRowDescriptor formRowDescriptorWithTag:@"phone" rowType:XLFormRowDescriptorTypePhone title:@"US Phone"]; | ||
row.valueFormatter = formatter; | ||
[row.cellConfigAtConfigure setObject:@(NSTextAlignmentRight) forKey:@"textField.textAlignment"]; | ||
|
||
row.useValueFormatterDuringInput = YES; | ||
[section addFormRow:row]; | ||
|
||
// Currency | ||
row = [XLFormRowDescriptor formRowDescriptorWithTag:@"currency" rowType:XLFormRowDescriptorTypeDecimal title:@"USD"]; | ||
CurrencyFormatter *numberFormatter = [[CurrencyFormatter alloc] init]; | ||
row.valueFormatter = numberFormatter; | ||
row.value = [NSDecimalNumber numberWithDouble:9.95]; | ||
[row.cellConfigAtConfigure setObject:@(NSTextAlignmentRight) forKey:@"textField.textAlignment"]; | ||
[section addFormRow:row]; | ||
|
||
// Accounting | ||
row = [XLFormRowDescriptor formRowDescriptorWithTag:@"percent" rowType:XLFormRowDescriptorTypeNumber title:@"Test Score"]; | ||
NSNumberFormatter *acctFormatter = [[NSNumberFormatter alloc] init]; | ||
[acctFormatter setNumberStyle:NSNumberFormatterPercentStyle]; | ||
row.valueFormatter = acctFormatter; | ||
row.value = @(0.75); | ||
[row.cellConfigAtConfigure setObject:@(NSTextAlignmentRight) forKey:@"textField.textAlignment"]; | ||
[section addFormRow:row]; | ||
|
||
section = [XLFormSectionDescriptor formSection]; | ||
[formDescriptor addFormSection:section]; | ||
|
||
return [super initWithForm:formDescriptor]; | ||
|
||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
PODS: | ||
- AFNetworking (2.5.2): | ||
- AFNetworking/NSURLConnection (= 2.5.2) | ||
- AFNetworking/NSURLSession (= 2.5.2) | ||
- AFNetworking/Reachability (= 2.5.2) | ||
- AFNetworking/Security (= 2.5.2) | ||
- AFNetworking/Serialization (= 2.5.2) | ||
- AFNetworking/UIKit (= 2.5.2) | ||
- AFNetworking/NSURLConnection (2.5.2): | ||
- AFNetworking/Reachability | ||
- AFNetworking/Security | ||
- AFNetworking/Serialization | ||
- AFNetworking/NSURLSession (2.5.2): | ||
- AFNetworking/Reachability | ||
- AFNetworking/Security | ||
- AFNetworking/Serialization | ||
- AFNetworking/Reachability (2.5.2) | ||
- AFNetworking/Security (2.5.2) | ||
- AFNetworking/Serialization (2.5.2) | ||
- AFNetworking/UIKit (2.5.2): | ||
- AFNetworking/NSURLConnection | ||
- AFNetworking/NSURLSession | ||
- AXRatingView (1.0.3) | ||
- JVFloatLabeledTextField (1.0.2) | ||
- SHSPhoneComponent (2.15) | ||
- XLDataLoader (1.1.0): | ||
- AFNetworking (~> 2.0) | ||
- XLForm (2.2.0) | ||
|
||
DEPENDENCIES: | ||
- AFNetworking (~> 2.0) | ||
- AXRatingView (= 1.0.3) | ||
- JVFloatLabeledTextField (= 1.0.2) | ||
- SHSPhoneComponent | ||
- XLDataLoader (~> 1.1) | ||
- XLForm (from `../../`) | ||
|
||
EXTERNAL SOURCES: | ||
XLForm: | ||
:path: ../../ | ||
|
||
SPEC CHECKSUMS: | ||
AFNetworking: fefbce9660acb17f48ae0011292d4da0f457bf36 | ||
AXRatingView: ccaadc1bbda99a4b7e1d556059482d2b933a9f4e | ||
JVFloatLabeledTextField: 58a3a32cfb800e5b224f676987e7c13abf50a14d | ||
SHSPhoneComponent: 4cec0653a150ad63cbc52b0c8b29ce2d3c9c26f0 | ||
XLDataLoader: 7d466e086f4b6ecd144e880be8232adbe80aef52 | ||
XLForm: 799e61ef230f519914e722bf032b19a597223c19 | ||
|
||
COCOAPODS: 0.36.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.