Support customizing brand images

This commit is contained in:
Klaas Pieter Annema 2015-11-19 12:01:49 -05:00
parent 6bc44beeed
commit 648d0cace7
2 changed files with 21 additions and 2 deletions

View File

@ -128,6 +128,9 @@
*/ */
- (void)clear; - (void)clear;
- (nullable UIImage *)cvcImageForCardBrand:(STPCardBrand)cardBrand;
- (nullable UIImage *)brandImageForCardBrand:(STPCardBrand)cardBrand;
/** /**
* Whether or not the form currently contains a valid card number, expiration date, and CVC. * Whether or not the form currently contains a valid card number, expiration date, and CVC.
* @see STPCardValidator * @see STPCardValidator

View File

@ -82,7 +82,7 @@ CGFloat const STPPaymentCardTextFieldDefaultPadding = 10;
_viewModel = [STPPaymentCardTextFieldViewModel new]; _viewModel = [STPPaymentCardTextFieldViewModel new];
_sizingField = [self buildTextField]; _sizingField = [self buildTextField];
UIImageView *brandImageView = [[UIImageView alloc] initWithImage:_viewModel.brandImage]; UIImageView *brandImageView = [[UIImageView alloc] initWithImage:[self brandImageForFieldType:STPCardFieldTypeNumber]];
brandImageView.contentMode = UIViewContentModeCenter; brandImageView.contentMode = UIViewContentModeCenter;
brandImageView.backgroundColor = [UIColor clearColor]; brandImageView.backgroundColor = [UIColor clearColor];
if ([brandImageView respondsToSelector:@selector(setTintColor:)]) { if ([brandImageView respondsToSelector:@selector(setTintColor:)]) {
@ -589,8 +589,24 @@ typedef void (^STPNumberShrunkCompletionBlock)(BOOL completed);
return NO; return NO;
} }
- (UIImage *)cvcImageForCardBrand:(STPCardBrand)cardBrand {
return self.viewModel.cvcImage;
}
- (UIImage *)brandImageForCardBrand:(STPCardBrand)cardBrand {
return self.viewModel.brandImage;
}
- (UIImage *)brandImageForFieldType:(STPCardFieldType)fieldType {
if (fieldType == STPCardFieldTypeCVC) {
return [self cvcImageForCardBrand:self.viewModel.brand];
}
return [self brandImageForCardBrand:self.viewModel.brand];
}
- (void)updateImageForFieldType:(STPCardFieldType)fieldType { - (void)updateImageForFieldType:(STPCardFieldType)fieldType {
UIImage *image = fieldType == STPCardFieldTypeCVC ? self.viewModel.cvcImage : self.viewModel.brandImage; UIImage *image = [self brandImageForFieldType:fieldType];
if (image != self.brandImageView.image) { if (image != self.brandImageView.image) {
self.brandImageView.image = image; self.brandImageView.image = image;