Git Product home page Git Product logo

bkmoneykit's Introduction

BKMoneyKit

iOS UI controls and formatters for entering money, credit card number and expiry date.

Card logo images by http://www.shopify.com/blog/6335014-32-free-credit-card-icons

Screenshots

Screenshot Screenshot

Classes

Class Description
BKCardNumberField Subclass of UITextField that supports formatting card number. You can show card logo image by setting showsCardLogo to YES.
BKCardNumberLabel Subclass of UILabel that displays formatted card number and card brand logo. You can mask card number by configuring cardNumberFormatter.
BKCardNumberFormatter Subclass of NSFormatter. This class has card number pattern information inside and formats according to patterns. You can customize masking behavior, masking character and group separater character.
BKCardExpiryField Subclass of UITextField that supports formatting card number expiry date.
BKCurrencyTextField Subclass of UITextField that supports formatting money amount. You can change currency by changing the currencyCode property of numberFormatter.

Examples

BKCardNumberField

// create (you can also use interface builder)
BKCardNumberField *cardNumberField = [[BKCardNumberField alloc] initWithFrame:CGRectMake(0, 0, 300, 40)];
cardNumberField.showsCardLogo = YES;
[self.view addSubview:cardNumberField];

// get card number
NSString *cardNumber = cardNumberField.cardNumber;

// get card company name
NSString *companyName = cardNumberField.cardCompanyName;

BKCardNumberLabel

BKCardNumberLabel *cardNumberLabel = [[BKCardNumberLabel alloc] initWithFrame:CGRectMake(0, 0, 300, 40)];
// set masking character. BLACK CIRCLE (0x25CF)
cardNumberLabel.cardNumberFormatter.maskingCharacter = @"โ—";
// masking second and third group.
cardNumberLabel.cardNumberFormatter.maskingGroupIndexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, 2)];

BKCardExpiryField

BKCardExpiryField *field = [[BKCardExpiryField alloc] init];

// get month
NSInteger month = field.dateComponents.month;

// get year
NSInteger year = field.dateComponents.year;

BKCurrencyTextField

BKCurrencyTextField *field = [[BKCurrencyTextField alloc] init];

// change currency
field.numberFormatter.currencyCode = @"KRW";

// get number value
NSDecimalNumber *number = field.numberValue;

Custom cards images

Just add to your image assets the card logo with the shortName eg. "visa", "amex", "mastercard" etc..

bkmoneykit's People

Contributors

bkook avatar brightsider avatar dcaunt avatar demetrio812 avatar edig avatar getaaron avatar glyuck avatar h4v1nfun avatar pinglamb avatar pronebird avatar sunhsiv 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

bkmoneykit's Issues

BKCurrencyTextField formats

Hi, how we can change BKCurrencyTextField formats, for ex: 44.333 like this one, or enable only integer types: 44,000 ?

Validation Methods + Expiration Date Year Length + Separator Style

Hi guys, congratulation so far!

Validation Methods:
I just wanted to tell you to if you can add a method which return a boolean if the credit card number, expiration date and cvv is in a valid format. I created it subclassing your class but would be better if you can add it directly in your code ;) Here the code:

    func isValidCCNumber() -> Bool {

        let ccNumberRegex = "^(([0-9]{4})[-|\\s| ]([0-9]{4})[-|\\s| ]([0-9]{4})[-|\\s| ]([0-9]{4}))|(([0-9]{4})[-|\\s| ]([0-9]{6})[-|\\s| ]([0-9]{5}))"
        let ccNumberPredicate = NSPredicate(format:"SELF MATCHES %@", ccNumberRegex)
        return ccNumberPredicate.evaluateWithObject(self.text!)
    }

    func isValidCCEpirationDate() -> Bool {

        let ccExpirationDateRegex = "(?:0[1-9]|1[0-2])\\/2[0-9]{3}"
        let ccExpirationDatePredicate = NSPredicate(format:"SELF MATCHES %@", ccExpirationDateRegex)
        return ccExpirationDatePredicate.evaluateWithObject(self.text!)
    }

    func isValidCCCvv() -> Bool {

        let ccCvvRegex = "^([0-9]{3,4})$"
        let ccCvvPredicate = NSPredicate(format:"SELF MATCHES %@", ccCvvRegex)
        return ccCvvPredicate.evaluateWithObject(self.text!)
    }

Expiration Date Year Length:
In my app I need to use 4 digit number in the textfield but actually your code allow just 2. Would be better if you can let the user decide the length.

Separator Style:
In your app you automatically add the separation in the credit card number, which is an whitespace, and in the cvv, which is an " / ". Would be better if you can let the user decide them.

Hope you'll include them ;)

Cheers,
Carmelo

New pod release

Hello,
can you please submit a new cocoapods release?

Thanks,
Dem

There is an issue when setting the card number programatically it doesn't update the card logo

If i set the card number programatically it doesn't update the card logo. It only updates when you set the card number via writing it directly from keyboard.

The following case does NOT work:

self.cardNumberField.text = numberOfCard

It updates the text in the field but it does NOT update the card logo, how can I do to make the card logo load in this case where I set the card number programatically ?

0.0.9 version doesn't compile when cocoapods is used

I added BKMokeyKit with help cocoapods. And when I try compile my project I have error:

BKMoneyKit/BKForwardingTextField.m:15:1: Cannot synthesize weak property because the current deployment target does not support weak references

If I change Deployment Target in BKMoneyKit my project will compile.

Cocoapods version is 1.1.0

Add Podspec

Can you add a podspec so this class can be used with CocoaPods?

Respect alignment

BKCurrencyTextField does not respect the horizontal text alignment set via storyboard

Formatting Manually

I'm trying to format the credit card number without setting the textfield class with BKCardNumberField. So I have typed this

   let bkcardNumberFormatter = BKCardNumberFormatter()

  func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {

    textField.text = bkcardNumberFormatter.formattedStringFromRawString(newString)
    return true
}

it is formatting but it is adding one more character in the end and can't delete text after whitespace. So please could you help me with it?

BKCurrencyTextField maximum fraction digits can not be 3.

Hi, thanks for sharing this great library.
I have problem with maximum fraction digits, when this number is equal to 3.
for ex in BKCurrencyTextField.m file:

_numberFormatter = [[NSNumberFormatter alloc] init];
_numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle;

    
    [_numberFormatter setMaximumFractionDigits:3];
    [_numberFormatter setCurrencyCode:@"KGS"];
    [_numberFormatter setCurrencySymbol:@""];
    [_numberFormatter setLocale:[NSLocale localeWithLocaleIdentifier:@"ru_RU"]];
    
    
    _nonNumericRegularExpression = [BKMoneyUtils nonNumericRegularExpression];
    _numberCharacterSet = [BKMoneyUtils numberCharacterSet];
    
    self.placeholder = [_numberFormatter stringFromNumber:@(0)];

in this case if press any number, for ex 9, then press 0(zero) nothing changes.
Another words when setMaximumFractionDigits:2 everything is ok, but when 3 there is a problem.

Wrong year if currentCalendar is NOT gregorian

Please check this situation since this returns invalid dates.
Expiration dates in credit card is in gregorian calendar.

To replicate just change the calendar in the settings to Japanese for example.

BKMoneyKit is breaking in iOS 10

The code is breaking when you pop or dismiss the view controller which has bkmoneykit textfields. Can you please fix this asap?

Entering numbers too quickly bypasses formatting

Tapping numbers too quickly in BKNumberField breaks formatting and is not recoverable unless the view is reloaded. I believe it's due to cardPatternInfo not being properly instantiated fast enough. We end up with BKCardNumberFormatter.cardPatternInfoWithNumberString returning nil and setting self.cachedPrefix and self.cardPatternInfo to nil. This then never recovers. I can try to find a solution, but don't have time at the moment. Just wanted to point it out for now.

Blank field user types character crash

If you have a blank BKCurrencyTextField and you try and type or paste a letter character rather than a number character it crashes the app.

Here's the error:

2016-03-16 15:34:32.494 Alder[68142:1267089] *** Terminating app due to uncaught exception 'NSDecimalNumberOverflowException', reason: 'NSDecimalNumber overflow exception'

0 CoreFoundation 0x0000000107d54e65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001077cddeb objc_exception_throw + 48
2 CoreFoundation 0x0000000107d54d9d +[NSException raise:format:] + 205
3 Foundation 0x000000010747db48 -[NSDecimalNumberHandler exceptionDuringOperation:error:leftOperand:rightOperand:] + 193
4 Foundation 0x000000010747c976 _checkErrorAndRound + 65
5 Foundation 0x000000010747cd46 -[NSDecimalNumber decimalNumberByDividingBy:withBehavior:] + 159
6 BKMoneyKit 0x00000001062e06ba -[BKCurrencyTextField textField:shouldChangeCharactersInRange:replacementString:] + 1370

BKCurrencyTextField does not send UITextField notifications

I really miss UITextFieldTextDidChangeNotification. :)

Since shouldChangeCharacters always returns NO, it would be great to add a manual notification.

[[NSNotificationCenter defaultCenter] postNotificationName:UITextFieldTextDidChangeNotification object:self];

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.