Add credit card item/cell

This commit is contained in:
Roman Efimov
2013-03-07 11:59:10 -06:00
parent 43b84f53c7
commit f0b402ea56
18 changed files with 232 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
//
// RETableViewCreditCardCell.h
// Meungry
//
// Created by Roman Efimov on 3/7/13.
// Copyright (c) 2013 Roman Efimov. All rights reserved.
//
#import "RETableViewCell.h"
#import "REFormattedNumberField.h"
#import "RECreditCardItem.h"
@interface RETableViewCreditCardCell : RETableViewCell <UITextFieldDelegate> {
UIView *_wrapperView;
}
@property (strong, nonatomic) RECreditCardItem *item;
@property (strong, nonatomic) REFormattedNumberField *creditCardField;
@property (strong, nonatomic) REFormattedNumberField *expirationDateField;
@property (strong, nonatomic) REFormattedNumberField *cvvField;
@property (assign, nonatomic) CGSize textFieldPositionOffset;
@property (strong, nonatomic) UIImageView *ccImageView;
@end

View File

@@ -0,0 +1,136 @@
//
// RETableViewCreditCardCell.m
// Meungry
//
// Created by Roman Efimov on 3/7/13.
// Copyright (c) 2013 Roman Efimov. All rights reserved.
//
#import "RETableViewCreditCardCell.h"
#import "RETableViewManager.h"
@implementation RETableViewCreditCardCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier tableViewManager:(RETableViewManager *)tableViewManager
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier tableViewManager:(RETableViewManager *)tableViewManager];
if (self) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.textLabel.backgroundColor = [UIColor clearColor];
_ccImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 5, 32, 32)];
_ccImageView.image = [UIImage imageNamed:@"RETableViewManager.bundle/Card_Stack"];
[self addSubview:_ccImageView];
_wrapperView = [[UIView alloc] initWithFrame:CGRectMake(60 + _textFieldPositionOffset.width, _textFieldPositionOffset.height + 1, self.frame.size.width - 70, self.frame.size.height)];
_wrapperView.clipsToBounds = YES;
[self addSubview:_wrapperView];
_creditCardField = [[REFormattedNumberField alloc] initWithFrame:CGRectMake(0, 0, 216, self.frame.size.height - _textFieldPositionOffset.height)];
_creditCardField.tag = 0;
_creditCardField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
_creditCardField.inputAccessoryView = self.actionBar;
_creditCardField.delegate = self;
_creditCardField.placeholder = @"1234 1234 1234 1234";
_creditCardField.format = @"XXXX XXXX XXXX XXXX";
[_creditCardField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
[_wrapperView addSubview:_creditCardField];
_expirationDateField = [[REFormattedNumberField alloc] initWithFrame:CGRectMake(320, 0, 80, self.frame.size.height)];
_expirationDateField.tag = 1;
_expirationDateField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
_expirationDateField.inputAccessoryView = self.actionBar;
_expirationDateField.format = @"XX/XX";
_expirationDateField.placeholder = @"MM/YY";
[_expirationDateField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
[_wrapperView addSubview:_expirationDateField];
_cvvField = [[REFormattedNumberField alloc] initWithFrame:CGRectMake(320, 0, 60, self.frame.size.height)];
_cvvField.tag = 2;
_cvvField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
_cvvField.inputAccessoryView = self.actionBar;
_cvvField.format = @"XXX";
_cvvField.placeholder = @"CVV";
[_cvvField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
[_wrapperView addSubview:_cvvField];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
if (selected) {
[_creditCardField becomeFirstResponder];
}
}
- (void)prepare
{
self.textLabel.text = self.item.title;
_textFieldPositionOffset = self.tableViewManager.style.textFieldPositionOffset;
_creditCardField.text = self.item.number;
_creditCardField.font = self.tableViewManager.style.textFieldFont;
_creditCardField.keyboardAppearance = self.item.keyboardAppearance;
_expirationDateField.text = self.item.expirationDate;
_expirationDateField.font = self.tableViewManager.style.textFieldFont;
_expirationDateField.keyboardAppearance = self.item.keyboardAppearance;
_cvvField.text = self.item.cvv;
_cvvField.font = self.tableViewManager.style.textFieldFont;
_cvvField.keyboardAppearance = self.item.keyboardAppearance;
}
- (void)layoutSubviews
{
[super layoutSubviews];
}
- (UIResponder *)responder
{
return _creditCardField;
}
#pragma mark -
#pragma mark UISwitch events
- (void)textFieldDidChange:(UITextField *)textField
{
if (textField.tag == 0) self.item.number = textField.text;
if (textField.tag == 1) self.item.expirationDate = textField.text;
if (textField.tag == 2) self.item.cvv = textField.text;
if (textField.tag == 0 && textField.text.length == 19) {
[_expirationDateField becomeFirstResponder];
__typeof(&*self) __weak weakSelf = self;
[UIView animateWithDuration:0.1 animations:^{
weakSelf.creditCardField.x = -120;
weakSelf.expirationDateField.x = CGRectGetMaxX(_creditCardField.frame);
weakSelf.cvvField.x = CGRectGetMaxX(_expirationDateField.frame);
}];
}
if (textField.tag == 0 && textField.text.length == 18) {
if (textField.tag == 0) {
__typeof(&*self) __weak weakSelf = self;
[UIView animateWithDuration:0.1 animations:^{
weakSelf.creditCardField.x = 0;
weakSelf.expirationDateField.x = 320;
weakSelf.cvvField.x = 320;
}];
}
}
if (textField.tag == 1 && textField.text.length == 5) {
[_cvvField becomeFirstResponder];
}
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
[self refreshActionBar];
return YES;
}
@end

View File

@@ -0,0 +1,27 @@
//
// RECreditCardItem.h
// Meungry
//
// Created by Roman Efimov on 3/7/13.
// Copyright (c) 2013 Roman Efimov. All rights reserved.
//
#import "RETableViewItem.h"
@interface RECreditCardItem : RETableViewItem
// Data and values
//
@property (copy, nonatomic) NSString *number;
@property (copy, nonatomic) NSString *expirationDate;
@property (copy, nonatomic) NSString *cvv;
// Keyboard
//
@property (nonatomic) UIKeyboardAppearance keyboardAppearance; // default is UIKeyboardAppearanceDefault
+ (id)item;
+ (id)itemWithNumber:(NSString *)number expirationDate:(NSString *)expirationDate cvv:(NSString *)cvv;
- (id)initWithNumber:(NSString *)number expirationDate:(NSString *)expirationDate cvv:(NSString *)cvv;
@end

View File

@@ -0,0 +1,41 @@
//
// RECreditCardItem.m
// Meungry
//
// Created by Roman Efimov on 3/7/13.
// Copyright (c) 2013 Roman Efimov. All rights reserved.
//
#import "RECreditCardItem.h"
@implementation RECreditCardItem
+ (id)item
{
return [[self alloc] init];
}
+ (id)itemWithNumber:(NSString *)number expirationDate:(NSString *)expirationDate cvv:(NSString *)cvv
{
return [[self alloc] initWithNumber:number expirationDate:expirationDate cvv:cvv];
}
- (id)initWithNumber:(NSString *)number expirationDate:(NSString *)expirationDate cvv:(NSString *)cvv
{
self = [super init];
if (!self)
return nil;
self.number = number;
self.expirationDate = expirationDate;
self.cvv = cvv;
return self;
}
- (BOOL)canFocus
{
return YES;
}
@end

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@@ -29,10 +29,12 @@
#import "RETableViewCell.h"
#import "RETableViewStringCell.h"
#import "RETableViewNumberCell.h"
#import "RETableViewCreditCardCell.h"
#import "REBoolItem.h"
#import "RETextItem.h"
#import "RENumberItem.h"
#import "RECreditCardItem.h"
@protocol RETableViewManagerDelegate;

View File

@@ -49,6 +49,7 @@
[self mapObjectClass:@"REBoolItem" toTableViewCellClass:@"RETableViewBoolCell"];
[self mapObjectClass:@"RETextItem" toTableViewCellClass:@"RETableViewTextCell"];
[self mapObjectClass:@"RENumberItem" toTableViewCellClass:@"RETableViewNumberCell"];
[self mapObjectClass:@"RECreditCardItem" toTableViewCellClass:@"RETableViewCreditCardCell"];
}
- (RETableViewSection *)addSection:(RETableViewSection *)section