Support customizing brand images
This commit is contained in:
parent
6bc44beeed
commit
648d0cace7
|
@ -128,6 +128,9 @@
|
|||
*/
|
||||
- (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.
|
||||
* @see STPCardValidator
|
||||
|
|
|
@ -82,7 +82,7 @@ CGFloat const STPPaymentCardTextFieldDefaultPadding = 10;
|
|||
_viewModel = [STPPaymentCardTextFieldViewModel new];
|
||||
_sizingField = [self buildTextField];
|
||||
|
||||
UIImageView *brandImageView = [[UIImageView alloc] initWithImage:_viewModel.brandImage];
|
||||
UIImageView *brandImageView = [[UIImageView alloc] initWithImage:[self brandImageForFieldType:STPCardFieldTypeNumber]];
|
||||
brandImageView.contentMode = UIViewContentModeCenter;
|
||||
brandImageView.backgroundColor = [UIColor clearColor];
|
||||
if ([brandImageView respondsToSelector:@selector(setTintColor:)]) {
|
||||
|
@ -589,8 +589,24 @@ typedef void (^STPNumberShrunkCompletionBlock)(BOOL completed);
|
|||
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 {
|
||||
UIImage *image = fieldType == STPCardFieldTypeCVC ? self.viewModel.cvcImage : self.viewModel.brandImage;
|
||||
UIImage *image = [self brandImageForFieldType:fieldType];
|
||||
if (image != self.brandImageView.image) {
|
||||
self.brandImageView.image = image;
|
||||
|
||||
|
|
Loading…
Reference in New Issue