mirror of
https://github.com/zhigang1992/RETableViewManager.git
synced 2026-05-14 16:19:27 +08:00
Merge branch 'creditCardCell'
This commit is contained in:
@@ -39,10 +39,27 @@
|
||||
@property (strong, readwrite, nonatomic) REFormattedNumberField *expirationDateField;
|
||||
@property (strong, readwrite, nonatomic) REFormattedNumberField *cvvField;
|
||||
|
||||
@property (strong, readwrite, nonatomic) UIImageView *ribbonExpired;
|
||||
|
||||
@end
|
||||
|
||||
@implementation RETableViewCreditCardCell
|
||||
|
||||
static inline BOOL isExpired(NSString *creditCardExpirationDate) {
|
||||
if([creditCardExpirationDate isEqualToString:@""])
|
||||
return NO;
|
||||
|
||||
NSDateFormatter *f = [[NSDateFormatter alloc] init];
|
||||
[f setDateFormat:@"MM/yy"];
|
||||
NSDate *cardDate = [f dateFromString:creditCardExpirationDate];
|
||||
|
||||
NSDateComponents *comp = [[NSCalendar currentCalendar] components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:[NSDate date]];
|
||||
[comp setDay:1];
|
||||
NSDate *firstDayOfMonthDate = [[NSCalendar currentCalendar] dateFromComponents:comp];
|
||||
|
||||
return [cardDate laterDate:firstDayOfMonthDate] == firstDayOfMonthDate;
|
||||
}
|
||||
|
||||
static inline NSString * RECreditCardType(NSString *creditCardNumber)
|
||||
{
|
||||
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\D" options:NSRegularExpressionCaseInsensitive error:NULL];
|
||||
@@ -125,7 +142,12 @@ static inline NSString * RECreditCardType(NSString *creditCardNumber)
|
||||
self.cvvField.placeholder = @"CVV";
|
||||
self.cvvField.delegate = self;
|
||||
[self.cvvField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
|
||||
|
||||
[self.wrapperView addSubview:self.cvvField];
|
||||
|
||||
self.ribbonExpired = [[UIImageView alloc] init];
|
||||
self.ribbonExpired.hidden = YES;
|
||||
[self.contentView addSubview:self.ribbonExpired];
|
||||
}
|
||||
|
||||
- (void)cellWillAppear
|
||||
@@ -150,6 +172,8 @@ static inline NSString * RECreditCardType(NSString *creditCardNumber)
|
||||
self.cvvField.text = self.item.cvv;
|
||||
self.cvvField.font = [UIFont systemFontOfSize:17];
|
||||
self.cvvField.keyboardAppearance = self.item.keyboardAppearance;
|
||||
|
||||
self.ribbonExpired.image = self.item.expiredRibbonImage;
|
||||
}
|
||||
|
||||
- (void)layoutSubviews
|
||||
@@ -174,6 +198,8 @@ static inline NSString * RECreditCardType(NSString *creditCardNumber)
|
||||
frame.size.height = self.contentView.frame.size.height;
|
||||
self.cvvField.frame = frame;
|
||||
|
||||
self.ribbonExpired.frame = CGRectMake(CGRectGetWidth(self.contentView.frame) - self.ribbonExpired.image.size.width + 1, -2, self.ribbonExpired.image.size.width, self.ribbonExpired.image.size.height);
|
||||
|
||||
if ([self.tableViewManager.delegate respondsToSelector:@selector(tableView:willLayoutCellSubviews:forRowAtIndexPath:)])
|
||||
[self.tableViewManager.delegate tableView:self.tableViewManager.tableView willLayoutCellSubviews:self forRowAtIndexPath:[self.tableViewManager.tableView indexPathForCell:self]];
|
||||
}
|
||||
@@ -266,6 +292,28 @@ static inline NSString * RECreditCardType(NSString *creditCardNumber)
|
||||
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
|
||||
{
|
||||
[self performSelector:@selector(flipCreditCardImageViewBack:) withObject:textField afterDelay:0.1];
|
||||
|
||||
if(textField == self.expirationDateField) {
|
||||
if(isExpired(self.expirationDateField.text)) {
|
||||
self.ribbonExpired.hidden = NO;
|
||||
} else {
|
||||
self.ribbonExpired.hidden = YES;
|
||||
}
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
|
||||
if (textField == self.expirationDateField) {
|
||||
if (range.location == 1) {
|
||||
NSInteger month = [NSString stringWithFormat:@"%@%@", self.expirationDateField.text, string].integerValue;
|
||||
if (month > 12) {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,10 @@
|
||||
|
||||
@interface RECreditCardItem : RETableViewItem
|
||||
|
||||
// Appearance customization
|
||||
//
|
||||
@property (copy, readwrite, nonatomic) UIImage *expiredRibbonImage;
|
||||
|
||||
// Data and values
|
||||
//
|
||||
@property (copy, readwrite, nonatomic) NSString *number;
|
||||
|
||||
@@ -45,6 +45,14 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
-(UIImage *)expiredRibbonImage {
|
||||
if (!_expiredRibbonImage) {
|
||||
_expiredRibbonImage = [UIImage imageNamed:@"ribbon_expired"];
|
||||
}
|
||||
|
||||
return _expiredRibbonImage;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Error validation
|
||||
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
30FE4162176A32C300F317B8 /* Single_Selected@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 30FE4159176A32C300F317B8 /* Single_Selected@2x.png */; };
|
||||
30FE4163176A32C300F317B8 /* Single@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 30FE415A176A32C300F317B8 /* Single@2x.png */; };
|
||||
53378ADE88FA40FD87184931 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5EA85FF11E7E458B98D5825C /* libPods.a */; };
|
||||
C59FC59F17FD77C2008333E9 /* ribbon_expired@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = C59FC59E17FD77C2008333E9 /* ribbon_expired@2x.png */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
@@ -231,6 +232,7 @@
|
||||
30FE4159176A32C300F317B8 /* Single_Selected@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Single_Selected@2x.png"; path = "Resources/Single_Selected@2x.png"; sourceTree = "<group>"; };
|
||||
30FE415A176A32C300F317B8 /* Single@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Single@2x.png"; path = "Resources/Single@2x.png"; sourceTree = "<group>"; };
|
||||
5EA85FF11E7E458B98D5825C /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
C59FC59E17FD77C2008333E9 /* ribbon_expired@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "ribbon_expired@2x.png"; sourceTree = "<group>"; };
|
||||
E4370D63D1564228A75E7BD2 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
@@ -483,6 +485,7 @@
|
||||
30FE415A176A32C300F317B8 /* Single@2x.png */,
|
||||
30D1C7D517AC08F3001F731C /* Single_Alt@2x.png */,
|
||||
30FE4159176A32C300F317B8 /* Single_Selected@2x.png */,
|
||||
C59FC59E17FD77C2008333E9 /* ribbon_expired@2x.png */,
|
||||
30EF93BB16E039B800B84981 /* InfoPlist.strings */,
|
||||
30939CDC17949A10004D95A9 /* Photos */,
|
||||
);
|
||||
@@ -554,6 +557,7 @@
|
||||
30FE4160176A32C300F317B8 /* Middle_Selected@2x.png in Resources */,
|
||||
30FE4161176A32C300F317B8 /* Middle@2x.png in Resources */,
|
||||
30FE4162176A32C300F317B8 /* Single_Selected@2x.png in Resources */,
|
||||
C59FC59F17FD77C2008333E9 /* ribbon_expired@2x.png in Resources */,
|
||||
30FE4163176A32C300F317B8 /* Single@2x.png in Resources */,
|
||||
30939CE917949A10004D95A9 /* photo1.jpg in Resources */,
|
||||
30939CEA17949A10004D95A9 /* photo2.jpg in Resources */,
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
Reference in New Issue
Block a user